【发布时间】:2018-11-08 01:32:12
【问题描述】:
我刚开始编写一些 Jest 测试,但在原本看起来完全正常的 Webpack/Babel 设置中立即遇到了“未知插件”错误,该设置在 npm run dev/npm run build 阶段运行良好.
具体来说,我收到的是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"
(当我在 Windows 上的 Git Bash 中时,错误会这样读取。)
我肯定安装了@babel/plugin-transform-async-to-generator。
我的package.json 的相关部分看起来像:
"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",
}
我的.babelrc很简单:
{
"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": {}
}
}
同样jest.config.js 直接来自jest --init:
module.exports = {
clearMocks: true,
coverageDirectory: "coverage",
testEnvironment: "jsdom"
};
对可能出现的问题有什么想法吗?
【问题讨论】:
标签: javascript webpack jestjs babeljs