reactjs - 开玩笑的错误,需要 Babel “^7.0.0-0”,但加载的是“6.26.3”
问题描述
对于我运行的每个 Jest 测试套件,我都会收到此错误:
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.
但奇怪的是,只有当我尝试通过npm install
. 那么问题是什么?我做错了什么?PS我不想用yarn install
。
这是我paskage.json
的 babel、jest 和酶相关部分:
{
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-proposal-decorators": "^7.2.3",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-flow": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-loader": "8.0.4",
"babel-plugin-react-docgen": "^2.0.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"jest-pnp-resolver": "1.0.1",
"jest-resolve": "23.6.0",
},
}
解决方案
Jest 23 不支持 @babel/core 7。要么升级到支持 babel 7 的 Jest 24 要么运行
npm install --save-dev babel-core@7.0.0-bridge.0
为 jest 23 加载兼容版本的 babel
推荐阅读
- c# - Xamarin.Forms 从 ListView 中删除项目并将其添加到另一个
- amazon-web-services - 我如何明确拒绝 lambda:InvokeFunction,但 IAM 的受信任资源除外?
- python - 使用 Dask 返回变异的输入
- c# - 将数据保存到数据库时出现外键约束错误
- react-admin - Api 平台分页自定义 page_parameter_name
- javascript - React 应用程序编译成功并且可以工作,但是在浏览器中重新加载页面后,我得到一个 TypeError var.filter is not a function
- android - 尝试在空对象引用上调用虚拟方法 'androidx.navigation.NavGraph androidx.navigation.NavDestination.getParent()'
- django-rest-framework - Django Rest Framework ModelSerializer 根据查询参数获取字段数据
- javascript - 如何遍历这些数组对象?
- python-3.x - 我让用户输入了一个支票号码,我想接受一个 CR 作为“0”