開始入坑RN,從最開始的學起不免有很多亂七八糟的問題,記錄在這裏。node
按照官網教程搭建開發環境並按照下面代碼運行時候有報錯,顯示8081端口的問題react
react-native init AwesomeProject cd AwesomeProject react-native run-ios
應該就是端口占用的問題,首先找到佔用程序,用下面代碼,加上sudo,若是什麼都沒有發生。能夠看到PID。ios
lsof -i :8081
而後用下面命令殺掉,也加上sudo。git
kill -9 <PID>
參考連接github
繼續運行又顯示報錯:npm
ERROR ENOENT: no such file or directory, lstat '/AwesomeProject/ios/build/ModuleCache/3F1D94PC0NUP2/AVFoundation-1M2ASOEW37WIZ.pcm-53d428b3'
{"errno":-2,"code":"ENOENT","syscall":"lstat","path":"/AwesomeProject/...json
在github找到解決方案,在工程中找到RCTWebSocket,移除build setting中custom compiler flags。以下圖:
react-native
參考連接緩存
npm WARN react-native@0.35.0 requires a peer of react@~15.3.1 but none was installed.
Unable to resolve module react/lib/ReactUpdates ...... Module does not exist in the module map or in theseapp
由於package.json依賴中react是^15.3.1,致使了版本不匹配的問題,因此改成~15.3.1,刪除node_modules,從新npm install,最後npm start -- --reset-cache,清理一下緩存。這樣再運行app便可順利進行。
_goToDetail = (rowData) => { const { navigator } = this.props; const imageUrl = `https:${rowData.imagePath}`; console.log("去商品詳情頁",rowData); if(navigator) { navigator.push({ component: ProductImageContainer, rowData: rowData }) } }