16

失败的插件是@babel/plugin-transform-regenerator(无边缘插件,160 万次下载/周)。

这是我的全部.babelrc

{
  "presets": [],
  "plugins": [
    "@babel/plugin-transform-regenerator"
  ]
}

当我尝试使用 parcel 对其进行转换时,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",

有任何想法吗?

4

4 回答 4

15

这是一个 babel 错误,基本上是说您已经定义了@babel/plugin-transform-regenerator两次插件 - 或多或少是间接的。

Parcel Bundler默认使用 Babel 预设转译您的代码@babel/preset-env。这些预设通常只是可共享的插件列表。正如你在这里看到的,preset-env已经包含"@babel/plugin-transform-regenerator"在 Babel 7 中。

"@babel/plugin-transform-regenerator"简单的解决方案:只需从您的插件配置中删除.babelrc.

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"]

我不得不删除 plugins和transform-object-rest-spread,正如所说的那样,它们包含在(此处明确指定)中。transform-async-generator-functionstransform-async-to-generatorenv

Babel 提供了一个很棒的升级工具,叫做babel-upgrade(surprise,surprise),它确实很好地完成了重命名插件的工作,但不幸的是它让我独自面对这些“重复”。

希望,这有帮助。

于 2018-11-29T18:20:39.313 回答
6

在做了一些研究后,最可能的错误原因是您有一个或多个默认插件,这些插件也在此插件内部使用。

解决问题的最简单方法是按照错误告诉您的操作:为插件添加唯一名称:

"plugins": ["@babel/plugin-transform-regenerator", {}, 'unique-name']

于 2018-10-16T18:15:21.133 回答
0

我今天也遇到了同样的问题。我解决这个问题的方法:

{
"presets": [
   "@babel/preset-env",
   "@babel/preset-react"
],
"plugins": [
    "transform-object-rest-spread",
    "transform-class-properties"
] 
}
于 2021-08-22T15:25:08.880 回答
0

只需"@babel/plugin-transform-regenerator"

"plugins": [
    "@babel/plugin-transform-regenerator"
]
于 2022-01-08T07:05:08.493 回答