Reputation: 1366
I'm just starting to write some Jest tests but have immediately run into an "unknown plugin" error in what otherwise appeared to be a fully working Webpack/Babel setup that functions fine at the npm run dev
/npm run build
stage.
Specifically, I'm getting ReferenceError: Unknown plugin "@babel/transform-async-to-generator" specified in "C:\\Users\\scott\\path\\to\\ThisProject\\.babelrc" at 0, attempted to resolve relative to "C:\\Users\\scott\\path\\to\\ThisProject"
(Error reads that way as I'm in Git Bash on Windows.)
I definitely have @babel/plugin-transform-async-to-generator
installed.
The relevant part of my package.json
looks like:
"scripts": {
"test": "jest",
"build": "webpack --mode=production",
"dev": "webpack --mode=development"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
},
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-async-to-generator": "^7.1.0",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"babel-loader": "^8.0.4",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
},
"devDependencies": {
"ajv": "^6.5.4",
"babel-jest": "^23.6.0",
"eslint": "^5.8.0",
"jest": "^23.6.0",
"jsdom": "^13.0.0",
}
My .babelrc
is very simple:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"ie": "11"
},
"useBuiltIns": "entry"
}
]
],
"plugins": [
"@babel/transform-async-to-generator",
"@babel/transform-arrow-functions",
"@babel/transform-modules-commonjs"
],
"env": {
"development": {},
"test": {},
"production": {}
}
}
Likewise jest.config.js
which is straight out of jest --init
:
module.exports = {
clearMocks: true,
coverageDirectory: "coverage",
testEnvironment: "jsdom"
};
Any ideas on what might be going wrong?
Upvotes: 1
Views: 1632
Reputation: 376
Try running npm install --save-dev babel-jest babel-core@^7.0.0-bridge @babel/core
, I believe the babel team released a bridge package to aid dependencies that are affected by the v7 upgrade.
See here for more info: https://github.com/facebook/jest/tree/master/packages/babel-jest#usage
Upvotes: 3