gpt4 book ai didi

babeljs - Babel 7 更新搞砸了 Cannot use the decorators and decorators-legacy plugin 的 Jest 测试

转载 作者:行者123 更新时间:2023-12-04 15:54:59 36 4
gpt4 key购买 nike

我正在升级到 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 来运行我的测试,因为没有它就无法开 Jest 。您认为这可能是问题所在?

  "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 文件中。

关于babeljs - Babel 7 更新搞砸了 Cannot use the decorators and decorators-legacy plugin 的 Jest 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52134173/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com