jest (babel) fails if using ES6 imports
See original GitHub issueEnvironment
devDependencies:
"@haul-bundler/babel-preset-react-native": "^0.13.2",
"@haul-bundler/cli": "^0.13.1",
"@haul-bundler/preset-0.60": "^0.13.0",
"jest": "^24.9.0",
Node v12.4.0
Description
After changing babel.config.js
preset @haul-bundler/babel-preset-react-native
jest tests don’t support import syntax anymore. If switching back to metro-react-native-babel-preset
jest works again.
Trying to figure out what setting is triggering this, but not expert in babel configuration.
Getting errors such as
import fetch, { Headers } from 'node-fetch';
^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
babel-jest doesn't handle ES6 within modules - Stack Overflow
Jest doesn't seem to have a problem using ES6 imports however as soon as it hits on an import statement within one of...
Read more >Configuring Jest
For example, with the following configuration jest will fail if there is less than 80% branch, line, and function coverage, or if there...
Read more >cannot use import statement outside a module jest - You.com
Jest doesn't support ES6 module and hence throwing this error when you directly run the test with Jest. if you want to run...
Read more >Setup and debug Jest to use ES6 imports in Node v12.x.x
Setup Babel to transpile our ES6 .js source code; Configure Babel so that Jest can use it; Setup VSCode to enable easy debugging....
Read more >Anyone gotten unit tests working with ES6 modules?
But if you really need Babel there are solutions in the forum that have Jest+Babel set ups but you'd likely need to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jounii Looks a bit hacky, you can alternatively try this:
It should work for every file if it’s being run by Jest, which sets
process.env.NODE_ENV
totest
.In next release of
@haul-bundler/babel-preset-react-native
CommonJS transform will be added automatically in whenNODE_ENV === 'test'
, like above.