15

The plugin that fails is @babel/plugin-transform-regenerator (no marginal plugin, 1.6 milion downloads / week).

This is my entire .babelrc:

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

When I try to transpile it with parcel using parcel build source/main/index.html --no-source-maps --out-dir build I get the following error:

/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)

Here are my versions from package.json:

"@babel/core": "^7.1.2",
"@babel/plugin-transform-regenerator": "^7.0.0",

Any ideas?

Rasto
  • 17,000
  • 40
  • 141
  • 232
  • 1
    I've never worked with any of this, but judging from the example given, you could try fixing it with `"plugins": ["@babel/plugin-transform-regenerator", {}]`. Though I highly doubt that will matter. A workaround might be to use `"plugins": ["@babel/plugin-transform-regenerator", {}, 'some-random-name']` so at least you're giving it a unique name. – icecub Oct 14 '18 at 02:51
  • @icecub That will probably work but it is really strange that something like this even happens... Where is the duplicated plugin comming from? – Rasto Oct 14 '18 at 02:55
  • 1
    From what I could find by doing a bit of research is that it might be possible that you have a couple of default plugins that are also used internally by this plugin. That causes the error mentioned. – icecub Oct 14 '18 at 03:04
  • @icecub Please make it an answer so that I can accept it for everybody else on the web to have a reference. – Rasto Oct 15 '18 at 21:59

2 Answers2

14

This is a babel error basically saying that you have defined your plugin @babel/plugin-transform-regenerator twice - more or less indirectly.

Parcel Bundler transpiles your code by default with the Babel preset @babel/preset-env. These presets in general are just shareable list of plugins. As you can see here, preset-env already includes "@babel/plugin-transform-regenerator" in Babel 7.

Simple solution: just delete "@babel/plugin-transform-regenerator" from your plugins config in .babelrc.

PS: had a similar experience, after migrating from version 6 to 7. My old config looked like this (valid in 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"]

I had to remove plugins transform-object-rest-spread, transform-async-generator-functions and transform-async-to-generator, which - as said - are included in env (here explicitely specified).

Babel offers a fantastic upgrade tool called babel-upgrade (surprise, surprise), that did get the job done well to rename the plugins, but unfortunately it left my alone with these "duplicates".

Hope, that helps.

ford04
  • 30,106
  • 4
  • 111
  • 119
4

After doing some research, the most likely cause of the error mentioned is that you have one or more default plugins that are also used internally by this plugin.

The easiest way to solve the issue is to do what the error tells you: Add a unique name to the plugin:

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

icecub
  • 7,964
  • 5
  • 34
  • 63