Unexpected token import when importing re-exported named exports
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
SyntaxError: Unexpected token import
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
The issue is with importing re-exported named exports. This repo demonstrates the issue:
git clone https://github.com/bali182/babel-jest-export-everything-bug
npm install
npm test
To summarize: package.json
{
"name": "babel-jest-export-everything-bug",
"scripts": {
"test": "jest --config .jestrc.json"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"jest": "^21.2.1"
}
}
.babelrc
{
"presets": [
[ "es2015", { "modules": "commonjs" } ],
"stage-0",
"react"
],
"plugins": [
"transform-decorators-legacy",
"transform-runtime"
]
}
.jestrc.json
{
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
}
namedExports.js
export const x = 1
export const y = 2
export const z = 3
reExports.js
export * from './namedExports'
export default { hello: 'world' }
reExports.test.js
import Foo, { x, y, z } from './reExports'
describe('testing re-exports', () => {
it('will never get to this method', () => {
expect(x).toBe(1)
})
})
Which then fails with
SyntaxError: Unexpected token import at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17) at Object.<anonymous> (src/reExports.test.js:1:120) at Generator.next (<anonymous>)
What is the expected behavior?
The transpilation to succeed and the test not to fail
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system. jest: 21.2.1 (couldn’t install latest because of #5156) node: v8.9.1 npm: 5.5.1
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top GitHub Comments
This issue may help you, https://github.com/babel/babel/issues/2877
@rickhanlonii Thanks for taking the time to look at this!
I fail to see though how this is a configuration issue. I’m trying to test JS with valid syntax, which transpiles with babel/webpack, but fails to do so (with the same babel config) when using Jest and the tooling around Jest.
As far as I can see I’m using everything Jest related correctly, and tests work properly except the case when importing re-exported named exports, as the title suggests.