失败的插件是@babel/plugin-transform-regenerator
(无边缘插件,每周 160 万次下载)。
这是我的整个.babelrc
:
{
"presets": [],
"plugins": [
"@babel/plugin-transform-regenerator"
]
}
当我尝试使用 parcel build source/main/index.html --no-source-maps --out-dir build
使用 parcel 转译它时,我收到以下错误:
/path/to/index.js: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
at assertNoDuplicates (/.../node_modules/@babel/core/lib/config/config-descriptors.js:205:13)
at createDescriptors (/.../node_modules/@babel/core/lib/config/config-descriptors.js:114:3)
at createPluginDescriptors (/.../node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
at alias (/.../node_modules/@babel/core/lib/config/config-descriptors.js:63:49)
at cachedFunction (/.../node_modules/@babel/core/lib/config/caching.js:33:19)
at plugins.plugins (/.../node_modules/@babel/core/lib/config/config-descriptors.js:28:77)
at mergeChainOpts (/.../node_modules/@babel/core/lib/config/config-chain.js:314:26)
at /.../node_modules/@babel/core/lib/config/config-chain.js:278:7
at buildRootChain (/.../node_modules/@babel/core/lib/config/config-chain.js:68:29)
at loadPrivatePartialConfig (/.../node_modules/@babel/core/lib/config/partial.js:85:55)
这是我在 package.json 中的版本:
"@babel/core": "^7.1.2",
"@babel/plugin-transform-regenerator": "^7.0.0",
有什么想法吗?
最佳答案
这是一个 babel 错误,基本上是说你定义了你的插件 @babel/plugin-transform-regenerator
两次 - 或多或少是间接的。
Parcel Bundler 转译您的代码 by default使用 Babel 预设 @babel/preset-env
。这些预设通常只是可共享的插件列表。如你所见here , preset-env
已经在 Babel 7 中包含了 "@babel/plugin-transform-regenerator"
。
简单的解决方案:只需从 .babelrc
中的插件配置中删除 "@babel/plugin-transform-regenerator"
。
PS:从版本 6 迁移到版本 7 后,我有类似的经历。我的旧配置如下所示(在 Babel 6 中有效)
"plugins": [
"react-hot-loader/babel",
"transform-object-rest-spread",
"transform-class-properties",
"transform-runtime",
"transform-async-generator-functions",
"transform-async-to-generator"
],
"presets": ["env", "react"]
我必须删除插件 transform-object-rest-spread
、transform-async-generator-functions
和 transform-async-to-generator
code>,如前所述,它包含在 env
中(此处明确指定)。
Babel 提供了一个很棒的升级工具,称为 babel-upgrade
(惊喜,惊喜),它确实很好地完成了重命名插件的工作,但不幸的是,它让我独自处理这些“重复项”。
希望对您有所帮助。
关于javascript - Babel 7 失败,单个插件显示 "Duplicate plugin/preset detected.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52798987/