javascript - 需要 Babel “7.0.0-0” 但加载了 “6.26.3”

标签 javascript reactjs react-native babeljs

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

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"
  }
}

最佳答案

您可能需要 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 的版本也来自该错误消息。

关于javascript - 需要 Babel “7.0.0-0” 但加载了 “6.26.3”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56990370/

相关文章:

javascript - 如何在 Eclipse 中设置速度跟踪器 (http ://code. google.com/p/speedtracer/) 开发环境

javascript - 通过 <p> 标签禁用文本自动 trim

reactjs - 如何在 ViteJS 和 React 中使用 autoprefixer?

javascript - 我可以使用 state AND props 来控制父/子之间的关系吗

user-interface - React JS 与 React Native

javascript - 使用 JavaScript 将按钮中的字符串添加到 HTML 字段

javascript - React HOC 适用于某些组件,但不适用于其他组件

php - POST 内容长度 167289889 字节超出了 41943040 字节的限制

android - 当 i18n.locale 更改时更改原生 android 上的启动图像

ios - React-native:Axios 不适用于 ios,但适用于 android。错误:NSNull 类型的 JSON 值 '<null>' 无法转换为 NSString