Requires Babel "^7.0.0-0",

Requires Babel "^7.0.0-0",

我的package.json

{

  "name": "immoc-koa",

  "version": "1.0.0",

  "description": "",

  "main": "index.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1",

    "dev": " npx nodemon src/index.js ",

    "server": "npx babel-node src/index.js",

    "hot": "npx nodemon --exec babel-node src/index.js",

    "debug:webpack": "npx node --inspect-brk ./node_modules/webpack/bin/webpack.js --inline --progress"

  },

  "keywords": [],

  "author": "",

  "license": "ISC",

  "dependencies": {

    "@koa/cors": "^3.0.0",

    "koa": "^2.11.0",

    "koa-body": "^4.1.1",

    "koa-combine-routers": "^4.0.2",

    "koa-helmet": "^5.2.0",

    "koa-json": "^2.0.2",

    "koa-router": "^7.4.0",

    "koa-static": "^5.0.0"

  },

  "devDependencies": {

    "@babel/core": "^7.7.7",

    "@babel/node": "^7.7.7",

    "@babel/preset-env": "^7.7.7",

    "babel-loader": "^8.0.6",

    "clean-webpack-plugin": "^3.0.0",

    "cross-env": "^6.0.3",

    "nodemon": "^2.0.2",

    "webpack": "^4.41.4",

    "webpack-cli": "^3.3.10",

    "webpack-node-externals": "^1.7.2"

  }

}



正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

3回答
提问者 前端祭酒师 2020-11-11 16:24:10

2020/11/11 最新的工程


"devDependencies": {

    "@babel/core": "^7.12.3",

    "@babel/node": "^7.12.1",

    "@babel/plugin-transform-runtime": "^7.12.1",

    "@babel/preset-env": "^7.12.1",

    "babel-loader": "^8.1.0",

    "clean-webpack-plugin": "^3.0.0",

    "copy-webpack-plugin": "^6.2.1",

    "css-loader": "^5.0.0",

    "eslint": "^7.11.0",

    "html-webpack-plugin": "^4.5.0",

    "mini-css-extract-plugin": "^1.2.0",

    "node-sass": "^4.14.1",

    "nodemon": "^2.0.6",

    "optimize-css-assets-webpack-plugin": "^5.0.4",

    "sass-loader": "^10.0.3",

    "style-loader": "^2.0.0",

    "terser-webpack-plugin": "^5.0.1",

    "webpack": "^4.43.0",

    "webpack-cli": "^3.3.11",

    "webpack-dev-server": "^3.11.0",

    "webpack-merge": "^5.3.0",

    "webpack-node-externals": "^2.5.2"

  },

  "dependencies": {

    "@babel/runtime": "^7.12.1",

    "@koa/cors": "^3.1.0",

    "@koa/router": "^9.4.0",

    "koa": "^2.13.0",

    "koa-body": "^4.2.0",

    "koa-combine-routers": "^4.0.2",

    "koa-compose": "^4.1.0",

    "koa-helmet": "^6.0.0",

    "koa-static": "^5.0.0"

  }


提问者 前端祭酒师 2019-12-23 21:04:35

原因:babel将前端环境更新到babel7,jest-babel之前是基于babel6的,执行时候就会报:Requires Babel “^7.0.0-0”, but was loaded with “6.26.3”.

est本身不支持es6语法,需要使用babel-jest插件进行转换

babel-jest不支持babel7版本

所以jest运行会报错,

后来在网上找到了解决方案:babel-core@^7.0.0-bridge.0插件

yarn add --dev babel-core@^7.0.0-bridge.0

当然你的项目中需要有@babel/core插件和babel-jest插件(其他babel相关插件自己按需配置)

可以认为babel-core@^7.0.0-bridge.0插件是将babel6衔接到babel7的一个桥梁



  • 您好 按照您的指示 安装了babel-core@^7.0.0-bridge.0插件 但是又出现了这个错误 [nodemon] app crashed - waiting for file changes before starting 不知您这边是否有同样的遭遇?
    2020-06-01 11:41:48
  • 提问者 前端祭酒师 回复 JasonCCCC #2
    不好意思 你是否解决了
    2020-11-11 16:22:10
提问者 前端祭酒师 2019-12-23 20:59:00

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: "D:\\project\\koa2\\immoc-koa\\node_modules\\@babel\\preset-env\\lib\\index.js")

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师