我有一个项目,该项目使用Parcel进行构建并使用Babel进行翻译。
当我开玩笑时,我得到
Test suite failed to run
ReferenceError: Unknown plugin "syntax-dynamic-import" specified in "/app/.babelrc" at 0, attempted to resolve relative to "/app"
通过Parcel正常运行时,可以成功找到该插件,并在我的package.json的依赖项中列出并安装。
我的babelrc:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/syntax-dynamic-import",
],
"env": {
"test": {
"plugins": ["dynamic-import-node"]
}
}
}
在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"
},
完整的项目代码可以在on Glitch中找到。重新混合项目以获得您自己的版本,您可以对其进行编辑并尝试在其上运行脚本。
答案 0 :(得分:0)
我得到了the following response when I posted this as a bug in the Jest GitHub repo。
在.babelrc中,我的插件应定义如下:
@babel/plugin-syntax-dynamic-import
由于我使用的是Jest 23,因此我需要安装babel-core@bridge
才能使用babel @ 7,否则我可以升级到Jest 24。