1.React-native Cannot find module 'invariant'
當(dāng)你執(zhí)行命令 react-native init AwesomeProject
想要新建一個(gè)項(xiàng)目時(shí)遇到這個(gè)問題,則是因?yàn)槟愕膎pm版本沒有適配最新的RN要求爱榔。
解決辦法:npm install -g npm
更新npm后即可 npm -v
可查詢npm版本
2.Invariant Violation:Application xxx has not been registered.
情況一:首先確定你沒有在運(yùn)行其他的RN項(xiàng)目汤锨,否則端口被占用是沒法注冊成功的
情況二:你真的注冊失敗了
檢查目錄下的index.ios.js
中
AppRegistry.registerComponent('xxx',() => ...);
與iOS項(xiàng)目文件目錄下的appDelegate.m
中
RCTRootView*rootView =[[RCTRootViewalloc]initWithBundleURL:jsCodeLocation
moduleName:@"xxx" launchOptions:launchOptions];
或是android工程文件下的MainActivity.java
中
mReactRootView.startReactApplication(mReactInstanceManager, "xxx", null);
沒有保持一致
解決方法:xxx
統(tǒng)一為你的項(xiàng)目名稱即可。
3.遇到舊項(xiàng)目中庫的函數(shù)返回值不對時(shí)凌蔬,位于RCTSRWebSocket.m
替代為下面的代碼:
int result = SecRandomCopyBytes(kSecRandomDefault, keyBytes.length, keyBytes.mutableBytes);
assert(result == 0);
替代為下面的代碼:
(void)SecRandomCopyBytes(kSecRandomDefault, sizeof(uint32_t), (uint8_t *)mask_key);