react-native運行ios報錯總結

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

其實如果報了這個錯,估計你安裝依賴的時候已經看到了一句警告:[email protected]" has incorrect peer dependency "[email protected]".但是被你忽略了,解決方法就是修改你現在安裝的react版本爲提示的版本:
yarn add [email protected]

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命令安裝,最後解決了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章