我需要帮助诊断并修复此错误:
"Error: only one instance of babel-polyfill is allowed"
我的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" ...
这个和我的webpack配置中的这个输入行:
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']
}
}
]}
答案 0 :(得分:9)
如果罪魁祸首是HtmlWebpackPlugin,则需要在实例化插件时添加选项<div class="flex-grid flex-gutter-5 six-columns">
<div class="flex-row">
<div class="flex-1-6-5 box">1</div>
<div class="flex-1-6-5 box">2</div>
<div class="flex-1-6-5 box">3</div>
<div class="flex-1-6-5 box">4</div>
<div class="flex-1-6-5 box">5</div>
<div class="flex-1-6-5 box">6</div>
</div>
</div>
<div class="flex-grid flex-gutter-5 five-columns" style="margin-top: 40px">
<div class="flex-row">
<div class="flex-1-6-5 box">1</div>
<div class="flex-1-6-5 box">2</div>
<div class="flex-1-6-5 box">3</div>
<div class="flex-1-6-5 box">4</div>
<div class="flex-1-6-5 box">5</div>
</div>
</div>
。某些没有此选项的配置会导致您构建的javascript代码加载两次。
答案 1 :(得分:3)
Only one instance of babel-polyfill is allowed
。
对于HtmlWebpackPlugin,您可以使用chunksSortMode手动对文件进行排序
使用"webpack": "^1.14.0"
:
new HtmlWebpackPlugin({
...
chunksSortMode: 'dependency',
...
}),
答案 2 :(得分:3)
Idempotent Babel Polyfill可以多次导入
从NPM安装
npm install --save idempotent-babel-polyfill
然后导入
import 'idempotent-babel-polyfill';
答案 3 :(得分:0)
可能你是从其他一些babel模块间接得到的。
可能的解决方案:
参考: https://github.com/babel/babel/issues/1019
评论由jameslk
无论如何我都明白了。看起来babel-runtime已经转移到babel-plugin-transform-runtime,这需要添加到插件列表中才能使用它。如果在某处记录下来会有所帮助。