React Native报错问题记录(多种解决方案,持续更新)
其实react-native相关问题多看看
https://github.com/reactnativecn/react-native-pushy/issues
还是能有效解决,百度还是比较浪费时间
【置顶】
!!!注意!!!:init 命令默认会创建最新的版本,而目前最新的 0.45 及以上版本需要下载 boost 等几个第三方库编译。这些库在国内即便翻墙也很难下载成功,导致很多人无法运行iOS项目!!!
- 解决:
中文网在论坛中提供了这些库的国内下载链接。如果你嫌麻烦,又没有对新版本的需求,那么可以暂时创建0.44.3
的版本。
提示:你可以使用
--version
参数(注意是两
个杠)创建指定版本的项目。例如react-native init MyApp --version 0.44.3
。注意版本号必须精确到两个小数点。
1, 问题: react-native run-ios报错,Error watching file for changes: EMFILE
Snip20180713_3.png- 解决:
brew uninstall watchman
// 报错a
brew uninstall --force watchman
brew cleanup --force -s watchman
brew prune
brew install watchman
// 报错b Error: An unexpected error occurred during the `brew link` step The formula built, but is not symlinked into /usr/local Permission denied @ dir_s_mkdir - /usr/local/Frameworks Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
brew install watchman
react-native run-ios
- 参考:
报错a
https://stackoverflow.com/questions/28225045/no-such-keg-usr-local-cellar-git
报错b
https://github.com/Homebrew/homebrew-core/issues/19286
2,问题:No bundle URL present
Simulator Screen Shot - iPhone X - 2018-07-13 at 11.06.30.png-
解决:
-
方法---1,(现在不管用)
Run "react-native run-ios"
When the error appears, run "npm install"
Then run "react-native run-ios" again.
check your hosts that 127.0.0.1 localhost is not delete
check that the network agent is not set up
then'npm install & react-native upgrade' to reset your project
3, The engine "node" is incompatible with this module (或Command yarn add react-native --exact failed.)
error react-native@0.56.0: The engine "node" is incompatible with this module
....
stderr: null,
stdout: null,
pid: 7395,
output: [ null, null, null ],
signal: null,
status: 1 }
Command yarn add react-native --exact failed.
- 解决:
更新node
### 第一步:使用npm安装n模块
* * *
n模块是专门用来管理nodejs版本的
sudo npm install -g n
> **提示 :** 如果不使用sudo作为前缀,很可能出现权限访问异常导致安装失败
### 第二步:升级nodejs
* * *
升级nodejs是有两种方法:
第一种是升级到最新版本
sudo n latest
第二种是升级到稳定版本
sudo n stable
> **提示 :** 建议是稳定版本
> 更多n模块管理请搜索【nodejs n模块使用说明】
- node升级参考:mac下nodejs 更新到最新版本的最新方法
4, TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
$ pushy uploadIpa <your-package.ipa>
当我使用目前最新的 node 版本(10.x.x)时会报错
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:124:9)
at Object.fs.write (fs.js:642:14)
at /Users/www/admin/build/webpack.dev.config.js:12:8
at FSReqWrap.oncomplete (fs.js:136:20)
- 解决:
类似于这样的错误,这是因为 node 版本太高了,我们需要降级,亲测降到 v8.11.1 可行,不过我发现此 bug 在前两天已经被 react-native-update 的维护者修复了,如果依然碰到这个问题,可以试试此方法。
5, 问题: pushy uploadIpa xxx.ipa
,Error: Validation error
-
解决:
你已经上传过同样版本号的ipa,重新上传需要修改版本号 -
参考:
https://github.com/reactnativecn/react-native-pushy/issues/143
6, 问题: npm install,Error: Cannot find module 'semver'
Snip20180802_16.png- 解决:
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf ~/.npm
brew uninstall --ignore-dependencies node
brew install node
7,问题:'config.h' file not found
- 解决:
$ rm -rf node_modules/ && yarn cache clean && yarn install
$ ls node_modules/react-native/ (missing third-party directory)
$ node_modules/react-native/ios-install-third-party.sh or node_modules/react-native/scripts/ios-install-third-party.sh
$ ls node_modules/react-native/ (third-party directory found)
-
参考:
Snip20180803_23.png
https://github.com/facebook/react-native/issues/14382
8, 集成react native到xcode,pod install 报错
~/Desktop/HuanXiangJiHua$ pod install
Analyzing dependencies
Fetching podspec for `CodePush` from `./ReactComponent/node_modules/react-native-code-push`
Fetching podspec for `DoubleConversion` from `./ReactComponent/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
Fetching podspec for `Folly` from `./ReactComponent/node_modules/react-native/third-party-podspecs/Folly.podspec`
Fetching podspec for `React` from `./ReactComponent/node_modules/react-native`
Fetching podspec for `glog` from `./ReactComponent/node_modules/react-native/third-party-podspecs/glog.podspec`
Fetching podspec for `yoga` from `./ReactComponent/node_modules/react-native/ReactCommon/yoga`
[!] CocoaPods could not find compatible versions for pod "Folly":
In Podfile:
Folly (from `./ReactComponent/node_modules/react-native/third-party-podspecs/Folly.podspec`)
Specs satisfying the `Folly (from `./ReactComponent/node_modules/react-native/third-party-podspecs/Folly.podspec`)` dependency were found, but they required a higher minimum deployment target.
[!] Automatically assigning platform `ios` with version `8.0` on target `Unity-iPhone` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
- 解决:
问题就在上面最后一句警告。
xcode项目使用的9.0和Folly的最低支持版本(9.0)不符.
需将xcode版本改为最低支持9.0
tips:
查看Folly的最低支持版本——用文本编辑器打开./ReactComponent/node_modules/react-native/third-party-podspecs/Folly.podspe能看到其最低支持的版本
9, Failed to connect to 127.0.0.1 port 1080: Connection refused
pod install (或 pod update)
- 报错信息
[!] Error installing Crashlytics
[!] /usr/bin/curl -f -L -o /var/folders/kz/p8_vcv1x0mn6x0wfmwy7z9d00000gn/T/d20180426-13131-1jlkxa7/file.zip https://kit-downloads.fabric.io/cocoapods/crashlytics/3.10.0/crashlytics.zip --create-dirs --netrc-optional
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 127.0.0.1 port 1080: Connection refused
cocopods 导入库 的时候时常被这个个错误困扰,
- 思路一:
网上的解决办法千篇一律,就是移除代理
不过对我没用。还是给出这个方案,也许对你有效
查询是否使用代理:git config --global http.proxy
取消代理:git config --global --unset http.proxy
- 思路二:
下面给出对我有效的方案
找到自己本机账号下面的.curlrc
文件,把它里面的 socks5 = "127.0.0.1:1080"
和 insecure
干掉
(注: 显示隐藏文件(终端
输入 defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder
)可以在finder本机账户看到隐藏文件 .curlrc
)
ps:暂未出现副作用,详细原因后续查明更新
感谢:# Error installing Crashlytics - SSL peer handshake failed [closed]
10, 'React/RCTBridgeModule.h' file not found
-
解决:
Snip20180921_4.png
11,"OBJC_CLASS$_ RCTBridge", referenced from: objc-class-ref in MT AppController.o
Snip20180921_6.png思路:pod install报的警告着手
[!] The `Unity-iPhone [Release]` target overrides the `OTHER_CFLAGS` build setting defined in `Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Unity-iPhone [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Unity-iPhone [Debug]` target overrides the `OTHER_CFLAGS` build setting defined in `Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Unity-iPhone [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
解决:
Snip20180925_1.png
12, The file “xxx” couldn’t be opened because you don’t have permission to view it
-
解决:
将info.plist 的 Bundle name As : (EXECUTABLE_NAME)
13, npm install 白色进度条卡住不动,安装卡住
解决:
1,❗️网上好多都是换镜像(对我这次不行,那就不是镜像的问题);
2,✅删除package-lock.json,node-modules,再执行npm install,问题解决(对我有效);
延伸:
为什么删除package-lock.json生效?
Snip20181022_13.png
14,react-native run-ios 运行报错:Print: Entry, ":CFBundleIdentifier", Does Not Exist
-
解决方案1:改为sudo react-native run-ios (Xcode10下,并不能彻底解决问题,能run success,但是不能安装应用到模拟器上)
参考:https://github.com/facebook/react-native/issues/14447 -
解决方案2:
在项目文件夹下执行:
第一步
cd node_modules/react-native/scripts && ./ios-install-third-party.sh && cd ../../../
第二步
cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh && cd ../../../../
⚠️注意:第二步命令“golg-0.3.5”需要改成你的glog版本
可以在以下文件夹查看你的golg (YourReactNativeProject ▸ node_modules ▸ react-native ▸ third-party
)
第三步重启服务:
npm start
参考: https://blog.csdn.net/chensenp/article/details/83543724