React Native 0.64.1回退后遇BigInt及AppRegistry报错求助
解决React Native回退版本后BigInt不存在及AppRegistry报错问题
问题场景
基于React Native 0.64.1的项目尝试升级至0.74.0失败,回退原版本并恢复暂存变更后启动项目,出现以下错误:
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle. ERROR ReferenceError: Property 'BigInt' doesn't exist, js engine: hermes ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
环境信息:NODE:14.15.4,NPM:6.14.10,JDK:11.0.23
已尝试过删除项目重新克隆、卸载Android Studio后重新克隆、执行修复命令、重置环境等操作,均未解决问题。
解决方案
1. 彻底清理依赖与构建缓存
- 清理npm缓存:
npm cache clean --force - 删除本地依赖与锁文件:
Windows系统执行:rm -rf node_modules rm package-lock.jsonrd /s /q node_modules del package-lock.json - 重新安装依赖:
npm install - 清理Android构建缓存:
cd android && ./gradlew clean && cd .. - 清理iOS构建缓存(若涉及iOS开发):
cd ios && pod deintegrate && pod install && cd ..
2. 锁定Hermes引擎版本匹配RN 0.64.1
RN 0.64.1对应的Hermes版本为^0.9.0,升级回退后可能残留高版本Hermes依赖,需手动锁定版本:
在package.json的dependencies中添加或修改:
"hermes-engine": "^0.9.0"
添加后重新执行npm install。
3. 校验入口文件与AppRegistry配置
- 确认
metro.config.js中的entryFile指向正确的入口文件(通常为index.js或index.tsx) - 检查入口文件的App注册代码是否正确:
import { AppRegistry } from 'react-native'; import App from './App'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App);
4. 恢复Hermes相关原生配置
升级RN 0.74时可能修改了Hermes的原生配置,回退后需恢复为RN 0.64.1的默认设置:
- Android:打开
android/app/build.gradle,确认Hermes配置:
确保project.ext.react = [ enableHermes: true, // 保持与原项目一致的开关状态 ]dependencies中未硬编码高版本的Hermes依赖。 - iOS:打开
ios/Podfile,确认Hermes配置:use_react_native!( :path => config[:reactNativePath], :hermes_enabled => true # 保持与原项目一致的开关状态 )
5. 切换至兼容的Node LTS版本
RN 0.64.1推荐使用Node 14.x LTS版本,当前14.15.4兼容,但可尝试切换至14.18.0(更稳定的LTS版本):
使用nvm管理版本:
nvm install 14.18.0 nvm use 14.18.0
切换后重新执行依赖安装与项目启动。
6. 清除Hermes字节码缓存
- Android:删除
android/app/build/generated/assets/react/release/和android/app/build/generated/sourcemaps/react/release/目录下的所有文件 - iOS:删除
ios/build目录下的所有内容
内容的提问来源于stack exchange,提问作者SurajTopal
相关产品推荐
相关产品推荐

