无论我尝试安装(无论如何)(无论是哪种方式),都应保持此错误,因为我遵循其他类似的报告。这是堆栈跟踪:
error: bundling failed: 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: "C:\\Users\\Admin-ESS\\Absent\\node_modules\\@babel\\preset-env\\lib\\index.js") at throwVersionError (C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\node_modules\@babel\helper-plugin-utils\lib\index.js:65:11) at Object.assertVersion (C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\node_modules\@babel\helper-plugin-utils\lib\index.js:13:11) at _default (C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\lib\index.js:150:7) at C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\node_modules\@babel\helper-plugin-utils\lib\index.js:19:12 at C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:317:46 at Array.map (<anonymous>) at OptionManager.resolvePresets (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20) at OptionManager.mergePresets (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10) at OptionManager.mergeOptions (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14) at OptionManager.init (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12) at File.initOptions (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\index.js:212:65) at new File (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\index.js:135:24) at Pipeline.transform (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\pipeline.js:46:16) at Object.transform (C:\Users\Admin-ESS\Absent\node_modules\metro\src\transformer.js:135:5) at Object.transformCode [as transform] (C:\Users\Admin-ESS\Absent\node_modules\metro\src\JSTransformer\worker\index.js:253:15) at execMethod (C:\Users\Admin-ESS\Absent\node_modules\jest-worker\build\child.js:92:29) at process.on (C:\Users\Admin-ESS\Absent\node_modules\jest-worker\build\child.js:42:7) at process.emit (events.js:180:13) at emit (internal/child_process.js:783:12)
和我的package.json:
{
"name": "Absent",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-preset-react-native-stage-0": "^1.0.1",
"jest": "^23.5.0",
"jest-react-native": "^18.0.0",
"react-test-renderer": "16.3.1"
},
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"test": "jest"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"@babel/core": "^7.0.0-rc.1",
"@babel/preset-env": "^7.0.0-rc.1",
"@babel/preset-react": "^7.0.0-rc.1",
"jail-monkey": "^1.0.0",
"prop-types": "^15.6.2",
"react": "16.3.1",
"react-native": "^0.55.4",
"react-native-device-info": "^0.22.4",
"react-native-elements": "^0.19.1",
"react-native-firebase": "^4.3.8",
"react-native-modal": "^6.5.0",
"react-native-router-flux": "^4.0.1",
"react-native-size-matters": "^0.1.2",
"react-native-vector-icons": "^5.0.0",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0"
},
"rnpm": {
"assets": [
"./assets/fonts/"
]
}
}
这里将非常感谢任何指针...
答案 0 :(得分:17)
好像您需要按照文档建议安装babel-core
:
https://jestjs.io/docs/en/getting-started#using-babel
yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime
答案 1 :(得分:8)
有时是因为您同时安装了 babel-cli和babel / cli 或 babel-core和@ babel / core 会引起冲突
所以
1)删除node_modules
2)从package.json中删除babel-cli,babel-core,保留@ babel / core,@ babel / cli
3)npm install
babel-cli 与 @ babel / cli
冲突圣经核心与 @ babel / core
冲突答案 2 :(得分:6)
测试使用cmd运行的版本
babel -V
如果不是版本7或更高版本
npm uninstall babel-cli -g
npm uninstall babel-core -g
还有
npm install @babel/cli -g
npm install @babel/core -g
如果您使用Jest run
npm install babel-core@7.0.0-bridge.0 --save-dev
卸载并重新安装@ babel / node可以解决如果您进行节点开发的问题。
答案 3 :(得分:4)
我在网上都找不到能解决问题的解决方案,我通过以下方式对其进行了修复:
jest
和@babel/core
(保留babel-core
v7网桥)答案 4 :(得分:2)
对于仍在战斗的人,四天前发布的Jest v24带有对babel 7的本地支持。
答案 5 :(得分:1)
从Babel文档中,我发现安装deps的顺序存在问题。
注意:请先在npx babel之前安装@ babel / cli和@ babel / core,否则npx将安装过期的babel 6.x。
根据用法docs。我发现从package.json
中删除两个项目并按顺序添加它们可以解决我的问题。奇怪的边缘情况。
答案 6 :(得分:0)
我这边的问题是babel-core
导入的babel-register
与@babel/core
之间存在冲突,Babel文档要求该文件用于最新用途并将其设置为root npm依赖项
似乎babel-register
已移至@babel/register
。 Babel并未使用新的模块名称更新文档,尽管他们对cli / core软件包进行了更新
以下是对我有用的setup babel doc的更新:
安装
npm install --save-dev @babel/register
用法
在package.json文件中进行以下更改:
{
"scripts": {
"test": "mocha --require @babel/register"
}
}
答案 7 :(得分:0)
我不小心在根目录中有一个名为.babelrc
的文件,其内容如下:
{
"presets": ["@babel/preset-env"]
}
删除该文件后,运行gulp
命令时不再出现此错误。
答案 8 :(得分:0)
有时,您具有本地版本,因此请将其删除,以便运行全局版本:
npm uninstall babel-cli
npm uninstall babel-core
答案 9 :(得分:0)
不建议全局安装babel。可能是您的IDE识别出了您全局安装的软件包,并且将基于该软件包。或者更可能的是您有相互冲突的软件包。例如babel-cli与@ babel / cli
发生冲突尽管您可以在计算机上全局安装Babel CLI,但最好逐个项目在本地安装它。
yarn remove global @babel/cli @babel/core
在项目目录中...
yarn remove babel-cli
yarn add @babel/cli @babel/core @babel/node --dev
答案 10 :(得分:0)
"devDependencies": {
"@babel/core": "^7.13.10",
"babel-core": "^7.0.0-bridge.0",
........
}
答案 11 :(得分:0)
你需要这 4 个包,这将解决问题:
npm install @babel/cli
npm install @babel/core
npm install @babel/node
npm install @babel/preset-env
答案 12 :(得分:-1)
node_modules
"devDependencies": {
"@babel/core": "^7.13.10",
"babel-core": "^7.0.0-bridge.0",
}
npm install