Babel 7失败,单个插件显示“检测到重复的插件/预设”。

Ras*_*sto 8 javascript babel npm babeljs parceljs

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

这是我的全部.babelrc

{
  "presets": [],
  "plugins": [
    "@babel/plugin-transform-regenerator"
  ]
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用包裹转运包裹时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)
Run Code Online (Sandbox Code Playgroud)

这是我来自package.json的版本:

"@babel/core": "^7.1.2",
"@babel/plugin-transform-regenerator": "^7.0.0",
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

ice*_*cub 5

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

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

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


for*_*d04 5

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

默认情况下,Parcel Bundler 使用Babel预设转换代码@babel/preset-env。这些预设通常只是插件的可共享列表。正如你可以看到这里preset-env已经包括"@babel/plugin-transform-regenerator"在巴别塔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"]
Run Code Online (Sandbox Code Playgroud)

我不得不删除插件transform-object-rest-spreadtransform-async-generator-functions并且transform-async-to-generator,其中-作为所述-包括在env(这里明确地规定)。

Babel提供了一个很棒的升级工具babel-upgrade(惊奇,惊喜),确实可以很好地完成对插件的重命名,但是不幸的是,我对这些“重复项”一无所知。

希望有帮助。