Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Only one instance of babel-polyfill is allowed" error

I need help diagnosing and fixing this error:

"Error: only one instance of babel-polyfill is allowed"

I have the following in my package.json:

"devDependencies": {
    "babel-core": "^6.23.1",
    "babel-jest": "^19.0.0",
    "babel-loader": "^6.3.2",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.23.0" ...

"dependencies": {
    "babel-polyfill": "^6.23.0" ...

And this and this entry line in my webpack config:

entry: ["babel-polyfill", path.resolve(APP_PATH, 'index')],
...
module: {
 rules: [
  {
    test: /\.js$/,
    exclude: /node_modules/,
    loader: 'babel-loader',
    query: {
      // specify that we will be dealing with React code
      presets: ['react', 'es2015']
    }
  }
]}
like image 694
foobar Avatar asked May 10 '17 20:05

foobar


Video Answer


2 Answers

Idempotent Babel Polyfill can be imported multiple times

Install from NPM

npm install --save idempotent-babel-polyfill

Then import it

import 'idempotent-babel-polyfill';
like image 181
Clay Risser Avatar answered Oct 15 '22 20:10

Clay Risser


If the culprit is HtmlWebpackPlugin, you need to add the option inject: false when instancing the plugin. Certain configurations without this option causes your built javascript code to be loaded twice.

like image 43
Aethix Avatar answered Oct 15 '22 19:10

Aethix