Reputation: 4019
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']
}
}
]}
Upvotes: 15
Views: 38267
Reputation: 1933
I had the same issue and I get rid of the error by removing require('babel-polyfill');
from the index.js script.
Upvotes: 0
Reputation: 3570
Idempotent Babel Polyfill can be imported multiple times
Install from NPM
npm install --save idempotent-babel-polyfill
Then import it
import 'idempotent-babel-polyfill';
Upvotes: 8
Reputation: 2308
Only one instance of babel-polyfill is allowed
usually appears if the order of files being wrapped isn't correct when making use of CommonsChunkPlugin or HtmlWebpackPlugin.
for HtmlWebpackPlugin you can manually sort your files with chunksSortMode
Using "webpack": "^1.14.0"
:
new HtmlWebpackPlugin({
...
chunksSortMode: 'dependency',
...
}),
Source: gdi2290 @ GitHub - 1 Jul. 2016 / 22 Jan. 2018
Upvotes: 3
Reputation: 119
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.
Upvotes: 11
Reputation: 350
Possibly you are getting it indirectly from some other babel module.
Possible Solutions:
reference: https://github.com/babel/babel/issues/1019
comment by jameslk
I figured it out anyway. It looks like babel-runtime has been moved to babel-plugin-transform-runtime and this needs to be added to the list of plugins to use it. Would of helped if that was documented somewhere.
Upvotes: 1