Jest - SyntaxError: Unexpected identifier
This worked for my simple set-up:
devDependencies (in package.json
):
"devDependencies": {
"babel-eslint": "^10.0.3",
"babel-preset-env": "^1.7.0",
"jest": "^24.9.0",
"parcel-bundler": "^1.12.3"
}
I simply created a babel.config.js
as follows:
// babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
Note - make sure to clear the cache before running!
Clear cache:
./node_modules/.bin/jest --clearCache
Lately I find that I don't need babel-jest
at all, and can get by simply with @babel/preset-env
, and the following .babelrc
:
{
"env": {
"test": {
"presets": [["@babel/preset-env"]]
}
}
}