Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 从“转换”时发出;巴别塔-preset-es2015“;至;巴别塔预设环境“;关于React和Webpack项目_Reactjs_Webpack_Babeljs_Babel Loader - Fatal编程技术网

Reactjs 从“转换”时发出;巴别塔-preset-es2015“;至;巴别塔预设环境“;关于React和Webpack项目

Reactjs 从“转换”时发出;巴别塔-preset-es2015“;至;巴别塔预设环境“;关于React和Webpack项目,reactjs,webpack,babeljs,babel-loader,Reactjs,Webpack,Babeljs,Babel Loader,我有一个React项目一直在使用babel-preset-es2015,该项目在webpack中构建得很好,但自从我移动到babel-preset env后,模块构建失败 出现以下错误消息: ERROR in ./src/index.js Module build failed: Error: Couldn't find preset "es2015" relative to directory "/path/to/project" at /path/to/project/node_mo

我有一个React项目一直在使用
babel-preset-es2015
,该项目在webpack中构建得很好,但自从我移动到
babel-preset env
后,模块构建失败

出现以下错误消息:

ERROR in ./src/index.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/path/to/project"
    at /path/to/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/path/to/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/path/to/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/path/to/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/path/to/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/path/to/project/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/path/to/project/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/path/to/project/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/path/to/project/node_modules/babel-loader/lib/index.js:50:20)
    at Object.module.exports (/path/to/project/node_modules/babel-loader/lib/index.js:175:20)
不工作(使用巴别塔预设环境)

package.json依赖项:

"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0"

所以我添加了一个.babelrc文件,并将加载程序选项移到了那里,现在一切似乎都很好。仍然不确定为什么它在webpack模块中不起作用

网页包

module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  },
  ...
};
.babelrc

{
  "presets": [
    "env",
    "react",
    "stage-1"
  ]
}

真奇怪。您是否尝试过删除
node\u模块并重新安装
npm
?是否更新了.babelrc文件?@Oblosys我有,但没有帮助。@Jaxx我没有.babelrc。如果我在网页包文件的“选项”下有预设,我是否需要一个?奇怪的是,根据您的错误,即使您切换到env,您的应用程序的某些部分仍会继续引用es2015预设。因此,这个错误并不是因为env预设不工作,而是由于一段过时的代码的干扰问题。你可以试试@Oblosys的建议。搜索“es2015”的完整项目也可能会发现一些有趣的东西。
module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  },
  ...
};
{
  "presets": [
    "env",
    "react",
    "stage-1"
  ]
}