失败的插件是@babel/plugin-transform-regenerator
(没有边际插件,每周下载1.6百万(。
这是我的全部.babelrc
:
{
"presets": [],
"plugins": [
"@babel/plugin-transform-regenerator"
]
}
当我尝试使用包裹转译它时parcel build source/main/index.html --no-source-maps --out-dir build
出现以下错误:
/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
两次 - 或多或少是间接的。
默认情况下,包裹捆绑器使用 Babel 预设@babel/preset-env
转译您的代码。这些预设通常只是可共享的插件列表。正如你在这里看到的,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
,如前所述 - 包含在env
中(此处明确指定(。
Babel 提供了一个名为babel-upgrade
(惊喜,惊喜(的出色升级工具,它确实很好地完成了重命名插件的工作,但不幸的是,它让我独自一人处理这些"重复项"。
希望,这有帮助。
经过一些研究,提到的错误最可能的原因是您有一个或多个默认插件,这些插件也由该插件在内部使用。
解决问题的最简单方法是执行错误告诉您的操作: 为插件添加一个唯一的名称:
"plugins": ["@babel/plugin-transform-regenerator", {}, 'unique-name']
我今天遇到了同样的问题。 我解决这个问题的方法:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"transform-object-rest-spread",
"transform-class-properties"
]
}
只需从中删除"@babel/plugin-transform-regenerator"
"plugins": [
"@babel/plugin-transform-regenerator"
]
我遇到了同样的问题,但使用另一个插件,我认为它们都是一样的。 我的插件:
@babel/plugin-proposal-object-rest-spread
最后我注意到devDependencies in package.json
和plugins in webpack.config.js
中都有一个插件。我摆脱了 webpack 文件中的那个,它运行良好。
但是,您的问题在于.babelrc
和package.json
。我认为如果你和我做同样的事情,它会解决的。您不必同时在两个文件中使用相同的插件。