Requires Babel \"^7.0.0-0\", but was loaded with \"6.26.3\"

FEvivi 2019-12-27

解决方法:

     每个人遇到该问题的根源可能不一样,我遇到的问题的解决方式是:

      --------------------------------------------------------------------------------------------

      npm install --save-dev @babel/core @babel/cli

      --------------------------------------------------------------------------------------------

      后来在结合webpack的过程中又出现了这个类似问题,这次使用的命令是:

      --------------------------------------------

     npm install --save-dev  babel-core babel-loader@8 babel-plugin-transform-runtime

      --------------------------------------------

  第一次实际上是因为cli报出的这个错,第二次是因为babel-loader报出的这个错,报的是不一样的,所以解决方式也不一样。

原因分析:

      报错中的“node_modules\babel-cli\”说明调用的是babel6的命令,而实际上7.0应该是这样的文件夹“node_modules\@babel\cli”,  babel7是以@开头的。

问题描述:

--------------------------------------------------------------------------------------------

Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel. (While processing preset: "E:\\newEflow\\workspace\\eetablestats\\web\\modules\\statsMain\\node_modules\\@babel\\preset-env\\lib\\index.js")

    at throwVersionError (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\@babel\helper-plugin-utils\lib\index.js:65:11)

    at Object.assertVersion (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\@babel\helper-plugin-utils\lib\index.js:13:11)

    at E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\@babel\preset-env\lib\index.js:91:7

    at E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\@babel\helper-plugin-utils\lib\index.js:19:12

    at E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\options\option-manager.js:317:46

    at Array.map (<anonymous>)

    at OptionManager.resolvePresets (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)

    at OptionManager.mergePresets (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)

    at OptionManager.mergeOptions (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)

    at OptionManager.init (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)

    at File.initOptions (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\index.js:212:65)

    at new File (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\file\index.js:135:24)

    at Pipeline.transform (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-core\lib\transformation\pipeline.js:46:16)

    at transform (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\util.js:50:22)

    at Object.compile (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\util.js:59:12)

    at write (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\dir.js:21:21)

    at handleFile (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\dir.js:43:7)

    at E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\dir.js:61:9

    at Array.forEach (<anonymous>)

    at handle (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\dir.js:59:29)

    at Array.forEach (<anonymous>)

    at module.exports (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\dir.js:69:15)

    at Object.<anonymous> (E:\newEflow\workspace\eetablestats\web\modules\statsMain\node_modules\babel-cli\lib\babel\index.js:129:1)

    at Module._compile (internal/modules/cjs/loader.js:959:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)

相关推荐