記錄下在react-native開發(fā)中遇到的錯誤
ReferenceError: Can't find variable: __fbBatchedBridge...
react-native啟動用來做JavaScript的代碼的服務(wù)桃移,是本地的服務(wù)拟赊,App默認(rèn)訪問的host地址是localhost
,運行到真實的設(shè)備上面的時候無法訪問react-native服務(wù),因此會出現(xiàn)上面的錯誤或南。
Android解決方案
- 對adb的server設(shè)置反向代理
adb reverse tcp:8081 tcp:8081
- 更改App內(nèi)的服務(wù)地址
- 搖晃手機(jī)
- 點擊菜單鍵
- 在電腦上面運行命令
adb shell input keyevent 82
在dev setting
里面即可設(shè)置帖世。
ios解決方案
在AppDelegate.m
中修改jsCodeLocation
:
.....
jsCodeLocation = [NSURL URLWithString:@"http://192.168.31.191:8081/index.ios.bundle?platform=ios&dev=true"];
....
watchman運行錯誤
錯誤信息:
ERROR: Unknown option --no-pretty
ERROR: Unknown option --no-pretty
Watchman: watchman--no-pretty get-sockname returned with exit code 1 ERROR: Unknown option --no-pretty
ERROR watchman--no-pretty get-sockname returned with exit code 1 ERROR: Unknown option --no-pretty
Error: watchman--no-pretty get-sockname returned with exit code 1 ERROR: Unknown option --no-pretty
at ChildProcess.<anonymous> (.../fb-watchman/index.js:198:18)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:852:16)
at Socket.<anonymous> (internal/child_process.js:323:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:492:12)
解決方法:
npm
下面的包也有watchman,如果安裝了先卸載
npm r -g watchman
重新安裝watchman
:
brew uninstall watchman
brew link pcre
brew install --HEAD watchman
如果出現(xiàn)下面的提示錯誤:
Error: The `brew link` step did not complete successfully
brew link --overwrite watchman
......
直接運行命令:
brew link --overwrite watchman
出現(xiàn)Linking創(chuàng)建的信息:
Linking /usr/local/Cellar/watchman/HEAD-bbd5957... 4 symlinks created
如果出現(xiàn)權(quán)限不足的情況,可以運行命令:
sudo chown -R
whoami
/usr/local