react-native运行ios报错总结

本文总结了React Native在iOS运行时可能出现的几个错误,包括找不到入口文件、NPM模块加载路径错误、ReactComponentTreeHook错误以及无bundle URL错误,并提供了相应的解决步骤,如清理node_modules、设置npm镜像、更新react版本以及处理第三方库的依赖问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cannot find entry file index.ios.js [index.android.js] in any of the roots

网上一搜出现这个问题的人还挺多,解决方法就是:
项目路径下运行:npm start -- -reset-cache
再重新启动项目:react-native run-ios(run-android)
如果还是失败那么就在这里看看有没有解决方案

NPM modules get required from /Users/node_modules/ instead of the project directory

同样的我还遇到了这个问题,就是node_modules里面的所有依赖文件目录都变成了/users/这种形式,解决方法:

  1. 删除 node_modules:rm -rf node_modules && npm install
  2. 清空watchman: watchman watch-del-all
  3. npm cache clean && npm install

如果还是失败那么就在这里看看有没有解决方案

如果还是解决不了,那么我猜你是不是用了cnpm install 而不是npm install?
或者说你用的是npm install ?

这两种安装方式都可能会导致问题,特别是cnpm!!在这里千万不能用。
推荐用的方式是:yarn

给npm设置淘宝镜像:

npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global

安装yarn: npm install yarn -g

给yarn设置淘宝镜像:

yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global

重新使用命令yarn 代替npm install,然后重新启动RN项目,应该就不会报错了。

ReactComponentTreeHook.purgeUnmountedComponents is not a function

其实如果报了这个错,估计你安装依赖的时候已经看到了一句警告:react-native@0.48.4" has incorrect peer dependency "react@16.0.0-alpha.12".但是被你忽略了,解决方法就是修改你现在安装的react版本为提示的版本:
yarn add react@16.0.0-alpha.12

No bundle URL present. Make sure you’re running a packager server or have included a .jsbundle file in your application bundle.

这个错误是模拟器红屏弹出的错误信息:

这里写图片描述

Xcode或者命令行提示的错误是:third-party/glog-0.3.4/src/base/mutex.h:105:10: fatal error: ‘config.h’ file not found,搜了一下解决办法:

删除ios/build路径,然后重新react-native run-ios

没有用,接着第二种办法:

删除node_modules/third-party,然后重新react-native run-ios

但是我的node_modules下根本没有这个插件,所以我用了最简单粗暴的方法:删除整个node_modules目录,然后重新使用yarn命令安装,最后解决了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值