【问题标题】:@babel/preset-env loaded with wrong babel version after upgrade babel 6 to 7@babel/preset-env 在升级 babel 6 到 7 后加载了错误的 babel 版本
【发布时间】:2019-03-17 05:50:07
【问题描述】:

我尝试将我的 babel 从 6 升级到 7,但遇到了这个问题。

/Users/darryl/Documents/Github/apps/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
        throw e;
        ^

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: "/Users/darryl/Documents/Github/apps/node_modules/@babel/preset-env/lib/index.js")
    at throwVersionError (/Users/darryl/Documents/Github/apps/node_modules/@babel/preset-env/node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
    at Object.assertVersion (/Users/darryl/Documents/Github/apps/node_modules/@babel/preset-env/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
    at _default (/Users/darryl/Documents/Github/apps/node_modules/@babel/preset-env/lib/index.js:154:7)
    at /Users/darryl/Documents/Github/apps/node_modules/@babel/preset-env/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
    at /Users/darryl/Documents/Github/apps/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:317:46
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/Users/darryl/Documents/Github/apps/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Users/darryl/Documents/Github/apps/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/darryl/Documents/Github/apps/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/darryl/Documents/Github/apps/node_modules/babel-register/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at compile (/Users/darryl/Documents/Github/apps/node_modules/babel-register/lib/node.js:103:45)
    at loader (/Users/darryl/Documents/Github/apps/node_modules/babel-register/lib/node.js:144:14)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/darryl/Documents/Github/apps/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

有人可以帮忙解释发生了什么吗? 我试图删除 node_modules 和 package-lock.json,并运行npm cache clean --force

但是这个错误还是出现了。 如何强制此依赖项(@babel/preset-env)在其依赖项中使用 Babel 7 而不是 Babel 6.26.3?

【问题讨论】:

  • 堆栈跟踪仍然提到babel-register,即 Babel 6。您需要使用 @babel/register
  • 这很奇怪,我在 package.json 中找不到这个 babel-register 作为 deps,这是其他依赖项的依赖项吗?那我需要在我的项目中安装它吗?
  • 我安装@babel/register 后似乎可以正常工作,谢谢@loganfsmyth!

标签: babeljs babel-plugin babel-preset-env


【解决方案1】:

正如loganfsmyth所说,做

npm i -D @babel/register

帮我解决我遇到的关于这个 babel-register 依赖项仍然使用 Babel 版本 6 的问题。

【讨论】:

    猜你喜欢
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 2021-03-03
    • 2017-12-20
    • 2018-09-06
    • 2018-04-27
    • 2018-07-02
    相关资源
    最近更新 更多