React Navite
問題匯總:
- /Users/xxx/Desktop/Finance/xxxx/ios/bundle/main.jsbundle: No such file or directory
- import <fishhook/fishhook.h> file not found
- import <RCTAnimation/RCTValueAnimatedNode.h> file not found
'config.h' file not found
'error:/Users/......./SupportFiles/main.jsbundle: No such file or directory'
'React/RCTBridgeModule.h' file not found
Could not build Objective-C module 'React'
1. main.jsbundle: No such file or directory
/Users/xxx/Desktop/Finance/PaishengFinance/ios/bundle/main.jsbundle: No such file or directory
解決方案:
方案一:使用如下命令生成 main.jsbundle,然后拖到項目中的bundle目錄下
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ./ios/bundle/main.jsbundle --assets-dest ./ios/bundle
其中我們常使用的一線命令選項:
-
--entry-file
,ios或者android入口的js名稱,比如index.js -
--platform
,平臺名稱(ios或者android) -
--dev
,設置為false的時候將會對JavaScript代碼進行優化處理。 -
--bundle-output
, 生成的jsbundle文件的名稱,比如./ios/bundle/main.jsbundle -
--assets-dest
圖片以及其他資源存放的目錄,比如./ios/bundle
解決方案二:把命令直接寫入npm script(package.json中)腳本中
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"bundle-ios":"react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ./ios/bundle/main.jsbundle --assets-dest ./ios/bundle"
},
然后在終端執行npm run bundle-ios
命令即可
修改RN入口代碼
- Debug Server上的設置
let jsCodeLocation = URL(string: "http://localhost:8081/index.bundle?platform=ios")
- 設置離線的jsCodeLocation
let jsCodeLocation = Bundle.main.url(forResource: "bundle/main", withExtension: "jsbundle")
- 如果在項目中使用了CodePush熱更新
let jsCodeLocation = CodePush.bundleURL()
溫馨提示:上傳代碼的時候,如果.gitignore
文件中有忽略*.jsbundle
后綴的,先把它注釋掉再上傳
2. #import <fishhook/fishhook.h> file not found
解決方案:在package.json文件腳本scripts中添加如下代碼
"fishhookinstall": "sed -I '' 's#<fishhook/fishhook.h>#\"fishhook.h\"#g' ./node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m",
然后終端執行:npm run fishhookinstall
或 npm run bundle-ios
3. #import <RCTAnimation/RCTValueAnimatedNode.h> file not found
解決方案:在package.json文件腳本scripts中添加如下代碼
"nodeinstall": "sed -I '' 's\/#import <RCTAnimation\\/RCTValueAnimatedNode.h>\/#import \"RCTValueAnimatedNode.h\"\/' ./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h",
然后終端執行:npm run nodeinstall
或 npm run bundle-ios
4. 'config.h' file not found
解決方案:
// 1. 進入腳本目錄,并運行腳本
cd node_modules/react-native/third-party/glog-0.3.4
../../scripts/ios-configure-glog.sh
// 2. 重新編輯運行即可
5. 'error:/Users/......./SupportFiles/main.jsbundle: No such file or directory'
// 1.項目根目錄下執行
npm run build-ios
// 2.把項目中舊的main.jsbundle和assets刪除,從bundle文件中重新拖進來,選項如下:
6. 'React/RCTBridgeModule.h' file not found
- (1). 進入scheme管理界面:Product -> Scheme -> Manage Scheme -> 雙擊你的項目;
- (2). 點擊‘ build’;
- (3). 取消'Parallelize Build'勾選;
- (4). 點擊“+”號,添加“React”庫;
- (5). 把添加的“React”庫,拖到最上面,再次運行即可;
7. Could not build Objective-C module 'React'
由于RN項目用pod引入了React相關的庫,運行的時候報Could not build Objective-C module 'React'
錯誤。
解決方案:
進入如下(個人/資源庫/Developer/Xcode/DerivedData/
)目錄,清空DerivedData目錄下的所以緩存文件,重新運行項目即可。
持續更新中……