Unexpected token export with Lodash
See original GitHub issueMinimal repo: https://github.com/epicfaace/jest-bug-1
- Issue My tests fail:
C:\Users\arama\Documents\My Web Sites\WordPress\wp-content\plugins\CFF\node_modules\lodash-es\lodash.js:10
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token export
My code:
import {set, unset, get, isArray} from 'lodash-es';
- My jest config:
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
I tried changing my jest config to the following, but it still doesn’t work:
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!lodash-es)"
]
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:23
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Jest setup "SyntaxError: Unexpected token export"
This seems like a hack because it takes over 1 minute to run a simple test that imports node_modules/lodash-es/lodash.js . reactjs · redux ......
Read more >jest lodash-es SyntaxError - Unexpected token export
Answers related to “jest lodash-es SyntaxError: Unexpected token export” · parsing error unexpected token javascript · popper.min. · jest invalid or unexpected ...
Read more >ts-jest syntaxerror: unexpected token 'export' - You.com | The search ...
I'm getting SyntaxError: Unexpected token 'export' on some node_modules , which are not transpiled (I guess?). I worked around this by adding these...
Read more >Jest setup "SyntaxError: Unexpected token export"-Reactjs
In your case, lodash-es specifically exposes ES modules, which will need to be built by Jest via babel. You can try narrowing your...
Read more >SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
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 Free
Top 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
lodash-esrequires transpilation to work properly on Node with commonjs.I.e. extend your transforms like this:
And use a
.babelrcin the root of your project with at least thetransform-es2015-modules-commonjsplugin defined:babel-jestshould already be installed due tojest, I’m not sure about the plugin - might be required to install this manually.@kulshekhar here it is! https://github.com/epicfaace/jest-bug-1