I have a project that works using Parcel to build and Babel to transpile.
When I try to run jest, I get
Test suite failed to run
ReferenceError: Unknown plugin "syntax-dynamic-import" specified in "/app/.babelrc" at 0, attempted to resolve relative to "/app"
The plugin is found successfully when running normally through Parcel, and is listed in my package.json's dependencies & installed.
My babelrc:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/syntax-dynamic-import",
],
"env": {
"test": {
"plugins": ["dynamic-import-node"]
}
}
}
In package.json:
"dependencies": {
"@material-ui/core": "^3.6.0",
"@material-ui/icons": "^3.0.1",
"express": "^4.16.4",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"jest": "^23.6.0",
"babel-jest": "^23.6.0",
"babel-plugin-dynamic-import-node": "^2.2.0"
},
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"http-proxy-middleware": "^0.19.0",
"less": "^2.0.0",
"parcel-bundler": "^1.10.3",
"parcel-plugin-eslint": "^1.0.4"
},
The full project code can be found on Glitch. Remix the project to get your own version that you can edit and attempt to run scripts on.
I got the following response when I posted this as a bug in the Jest GitHub repo.
In .babelrc, my plugin should be defined like this:
@babel/plugin-syntax-dynamic-import
and since I'm using Jest 23, I need to install babel-core@bridge
to use babel@7 or I can upgrade to Jest 24.