【问题标题】:Requires Babel “7.0.0-0” but was loaded with “6.26.3”需要 Babel “7.0.0-0” 但加载了 “6.26.3”
【发布时间】:2019-07-11 13:28:06
【问题描述】:

每当我运行程序时,我都会收到此错误:

ERROR in ./index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
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.
    at throwVersionError (E:\ReactJS final\node_modules\@babel\helper-plugin-utils\lib\index.js:65:11)
    at Object.assertVersion (E:\ReactJS final\node_modules\@babel\helper-plugin-utils\lib\index.js:13:11)
    at _default (E:\ReactJS final\node_modules\@babel\plugin-proposal-object-rest-spread\lib\index.js:51:7)
    at E:\ReactJS final\node_modules\@babel\helper-plugin-utils\lib\index.js:19:12
    at Function.memoisePluginContainer (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\options\option-manager.js:113:13)
    at Function.normalisePlugin (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\options\option-manager.js:146:32)
    at E:\ReactJS final\node_modules\babel-core\lib\transformation\file\options\option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
    at OptionManager.mergeOptions (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
    at OptionManager.init (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
    at File.initOptions (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\index.js:212:65)
    at new File (E:\ReactJS final\node_modules\babel-core\lib\transformation\file\index.js:135:24)
    at Pipeline.transform (E:\ReactJS final\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
    at transpile (E:\ReactJS final\node_modules\babel-loader\lib\index.js:50:20)
    at Object.module.exports (E:\ReactJS final\node_modules\babel-loader\lib\index.js:173:20)
i 「wdm」: Failed to compile. 

请帮我解决这个问题。 (我这里也附上了 package.json 文件)

{
  "name": "reactjs-final",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "it": "webpack-dev-server --hot"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/plugin-proposal-object-rest-spread": "^7.5.1",
    "@babel/preset-env": "^7.5.4",
    "babel-loader": "^7.1.5",
    "babel-preset-stage-0": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "webpack": "^4.33.0",
    "webpack-cli": "^3.3.3",
    "webpack-dev-server": "^3.7.0"
  },
  "dependencies": {
    "@babel/cli": "^7.5.0",
    "@babel/core": "^7.5.4",
    "@deck.gl/core": "^7.0.0",
    "@deck.gl/mapbox": "^7.1.4",
    "@fortawesome/fontawesome-free": "^5.9.0",
    "@mapbox/mapbox-gl-geocoder": "^4.4.0",
    "@mapbox/mapbox-sdk": "^0.6.0",
    "@mapbox/react-geocoder": "^2.5.0",
    "axios": "^0.19.0",
    "babel-core": "^6.26.3",
    "babel-install": "^2.1.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "debounce": "^1.2.0",
    "deck.gl": "^7.1.4",
    "dotenv": "^8.0.0",
    "formik": "^1.5.7",
    "http-proxy-middleware": "^0.19.1",
    "install-peers": "^1.0.3",
    "mapbox-gl": "^0.47.0",
    "npm-autoinstaller": "^1.3.1",
    "randomcolor": "^0.5.4",
    "raw-loader": "^3.0.0",
    "react": "^16.8.6",
    "react-autocomplete": "^1.8.1",
    "react-dom": "^16.8.6",
    "react-geocoder-mapbox": "^2.5.12",
    "react-google-recaptcha": "^1.0.5",
    "react-helmet": "^5.2.1",
    "react-loading-skeleton": "^1.1.2",
    "react-map-gl": "^5.0.3",
    "react-map-gl-geocoder": "^2.0.5",
    "react-mapbox-gl-geocoder": "^1.0.3",
    "react-modal": "^3.8.2",
    "react-redux": "^7.1.0",
    "react-router-dom": "^5.0.1",
    "react-router-ga": "^1.2.0",
    "react-router-hash-link": "^1.2.1",
    "react-scripts": "^3.0.1",
    "react-text-loop": "^2.0.2",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "uikit": "^3.1.6"
  }
}

【问题讨论】:

  • 删除node_modules文件夹并运行npm i,以确保一切正常
  • 不会影响我的其他部分代码吗?
  • node_modules 是一个文件夹,用于保存所有下载的包,包括babelpackage.json 中的其他包。删除并运行npm i 就像“重新安装”软件包一样。
  • 好的,我会试试的。
  • 检查我的答案,它会工作

标签: javascript reactjs react-native babeljs


【解决方案1】:

您可能需要 babel 7 桥作为 babel-core 的版本

"babel-core": "^7.0.0-bridge.0"

在你的package.json

您可以查看package-lock.json 并查看那里安装了babel-core 的哪个版本。如果它仍在安装6.26.3,您可能有另一个需要更新的特定版本的软件包。在我的情况下,它是 jest 以及 babelify 到最新版本支持 babel 7 以阻止它在我的 package-lock.json 中安装较旧的 babel 版本。听起来您也确实需要从该错误消息中更新您的 babel-loader 版本。

【讨论】:

    【解决方案2】:

    在您的package.json 中有这两个包。

    {
        "@babel/core": "^7.5.4",
        ...
        "babel-core": "^6.26.3",
    }
    

    They are the same package 但最后一个是以前的版本。

    编辑:

    你还需要更新babel-loader

    "babel-loader": "^8.0.6" 可以工作。

    【讨论】:

    • 现在,出现此错误: ./index.js 中的错误模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):错误:找不到模块 'babel-核心'
    • @Sagar 删除后是否运行过npm i?另请查看我添加的链接,该链接解释了 @babel/corebabel-core
    【解决方案3】:

    当我实际将 babel-cli 更改为版本 7 时,它对我有用,所以问题可能就在那里

    【讨论】:

      猜你喜欢
      • 2019-01-23
      • 2019-06-06
      • 2019-10-30
      • 2019-04-18
      • 2019-05-13
      • 1970-01-01
      • 2019-08-09
      • 2019-05-18
      • 1970-01-01
      相关资源
      最近更新 更多