gpt4 book ai didi

react-native - 预设选项中不允许 Babel 覆盖 react 原生导航

转载 作者:行者123 更新时间:2023-12-05 00:11:50 25 4
gpt4 key购买 nike

我想添加一个路由器 react native navigation v2react-native 上的这个启动项目,但我有一个与 babel 包有关的问题(可能)。当我跑

react-native run-android

我在 Metro Bundler 中有这个错误:

loading dependency graph, done. : bundling failed: Error: [BABEL] D:\react—native\projecti\index.js: .overr ides is not allowed in preset options

at Object.keys.forEach.key (D:\react—native\projecti\node_modules\metro\node odules\Obabel\core\lib\config\validation\options.js:71:13) at Array.forEach () at validate (D:\react—native\projecti\node_modules\metro\node_modules\nabel core\lib\config\validation\options.js:69:21) at instantiatePreset (D:\react—native\projecti\node_modules\metro\node_modul s\l@babel\core\lib\config\full.js:242:36) at cachedFunction (D:\react—native\projecti\node_modules\metro\node_modules\ babel\core\lib\config\caching.js:42:19) at loadPresetDescriptor (D:\react—native\projecti\node_modules\metro\node_mo Iules\ftabel\core\lib\config\full.js:233:45) at config.presets.map.descriptor (D:\react—native\projecti\node_modules\metr I\node_modules\ftabel\core\lib\config\full.js:68:19) at Array.map () at recurseDescriptors (D:\react—native\projecti\node_modules\metro\node_modu les\Obabel\core\lib\config\full.js:66:38)



在控制台中构建成功结束。

我的 package.json
{
"name": "project1",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug"
},
"dependencies": {
"@babel/runtime": "^7.1.2",
"react": "16.5.0",
"react-native": "0.56",
"react-native-navigation": "^2.0.2569"
},
"devDependencies": {
"@babel/core": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23",
"babel-preset-react-native": "^5",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.47.0",
"react-test-renderer": "16.5.0"
},
"jest": {
"preset": "react-native"
}
}

.babelrc
{
"presets": [
"@babel/preset-env",
"module:metro-react-native-babel-preset"
]
}

最佳答案

看起来你有 RN 0.56,它使用了 babel 的一些 beta 版本。

我看到你有两个解决方案:

1) 保持 RN 0.56 并设置正确的 babel deps

对于 RN 0.56,您需要确保所有 @babel/* deps 都在 7.0.0-beta.47 版本中得到修复(请参阅 0.56 的更改日志)

2) 将您的项目升级到 RN 0.57

为了能够使用最新的 babel 7 依赖项,您必须将项目迁移到 RN 0.57。

This is what I have for a 0.57.1 project:

"dependencies": {
"react": "16.5.0",
"react-native": "0.57.1",
.......
}

"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-preset-react-native-stage-0": "^1.0.1",
.....

}

重要 :更新 .babelrc配置为:
{
"presets": ["module:metro-react-native-babel-preset"]
}

有关 RN 0.56、0.57 更改日志的更多信息,请访问:

https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md

更多关于 babel 7 deps 的信息在这里:

https://new.babeljs.io/docs/en/next/v7-migration.html#versioning-dependencies-blog-2017-12-27-nearing-the-70-releasehtml-peer-dependencies-integrations
https://github.com/babel/babel-upgrade

有关将 RN 项目升级到 babel 7 的更多信息,请访问:

React native upgrade from babel 6 to babel 7

注意:确保在 babel 版本修改后删除所有 node_modules 并重新安装它们并清理本地缓存。
rm -rf $TMPDIR/react-*; rm -rf $TMPDIR/haste-*; rm -rf $TMPDIR/metro-*; watchman watch-del-all

关于react-native - 预设选项中不允许 Babel 覆盖 react 原生导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52632683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com