【发布时间】:2017-10-09 16:32:09
【问题描述】:
我需要帮助诊断和修复此错误:
"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']
}
}
]}
【问题讨论】:
-
看起来罪魁祸首是我的 webpack 配置中的 HtmlWebpackPlugin。如果我删除这个插件,错误就会消失。
-
尝试将 entry: ["babel-polyfill", path.resolve(APP_PATH, 'index')] 更改为 entry: [path.resolve(APP_PATH, 'index')]
-
我正在使用 babel-polyfill,所以我需要将它放在某个地方。我也可以在某处添加导入,但我得到了同样的错误。如果我删除它,我会收到错误:Uncaught ReferenceError: regeneratorRuntime is not defined.
标签: reactjs webpack babeljs babel-polyfill