babeljs - Babel 7 更新了无法同时使用装饰器和装饰器遗留插件的玩笑测试
问题描述
我正在升级到 Babel 7,虽然应用程序正在加载,但我的测试却搞砸了。他们以前很好。我从涉及装饰组件的每个测试中都收到此错误。
FAIL src/app/components/pages/Home/__tests__/Home.test.js
● Test suite failed to run
Cannot use the decorators and decorators-legacy plugin together
at validatePlugins (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:10401:13)
at getParser (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:10464:5)
at parse (node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:10448:12)
at parser (node_modules/@babel/core/lib/transformation/normalize-file.js:170:34)
at normalizeFile (node_modules/@babel/core/lib/transformation/normalize-file.js:138:11)
at runSync (node_modules/@babel/core/lib/transformation/index.js:44:43)
at transformSync (node_modules/@babel/core/lib/transform.js:43:38)
at transform (node_modules/@babel/core/lib/transform.js:22:38)
.babelrc 请注意:我正在使用 remove-decorators 来运行我的测试,因为没有它就无法开玩笑。你认为这可能是问题所在?
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
["@babel/plugin-proposal-decorators", { legacy: true } ],
"babel-plugin-styled-components"
],
"env": {
"development": {
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
["@babel/plugin-proposal-decorators", { legacy: true } ],
"babel-plugin-styled-components"
]
},
"test": {
"plugins": [
"remove-decorator"
]
}
包.json
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^21.2.0",
"babel-loader": "^8.0.0",
"babel-plugin-remove-decorator": "^1.0.0",
"babel-plugin-styled-components": "^1.3.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "6.26.0",
解决方案
我解决了这个问题npm install -D @babel/plugin-proposal-decorators
并且
"test": {
"plugins": [["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }], "remove-decorator"]
}
将此添加到我的babel.conf.js
文件中。
推荐阅读
- android - NDK 中的“结构中的可变长度数组”错误
- python-3.x - 格式化文本文件中的数据
- r - 尝试从 R/Bioconductor 中的 GO ID 检索 Go 术语时出错
- gradle - 将变量从 Groovy 类传回 Gradle 任务
- javascript - mysql 的输出不会在表上正确显示
- javascript - 量角器,登录表单上的 sendkeys() 不起作用。浏览器不显示表单字段的值
- java - 在具有多种组合的 xml 文件中使用 PointCut 表达式
- php - 如何跳转到循环的开头?
- android - 蓝牙发现同一设备 10 次
- java - 如何将视频从我的自定义相机返回到 Messenger