React Native 遇到的坑(持續(xù)更新)

  1. Module @babel/runtime/helpers/interopRequireDefault does not exist in the Haste module map
loading error

解決方案:

npm install --save-dev @babel/core
npm install --save-dev @babel/runtime
or with yarn:
yarn add --dev @babel/core
yarn add --dev @babel/runtime
//若還是失敗
npm run start --reset-cache
or
react-native start --reset-cache

facebook react-native issues的解決方案

  1. The module ./../react-transform-hmr/lib/index.js could not be found from /Users/xxx/Documents/TestProject/RNApplication/App.js
    解決方案:
#react-native start --reset-cache
#react-native start 
//重新打開一個(gè)終端窗口
#react-native run-android`
# or
# react-native run-ios

stackoverflow中的issue

  1. Application iOSRN- has not been registered.
NSURL * jsCodeLocation;

    NSString * strUrl = @"http://localhost:8081/index.bundle?platform=ios&dev=true";
    jsCodeLocation = [NSURL URLWithString:strUrl];

    
    NSDictionary *params = @{@"componentName":@"MeApp1", @"args":@{@"params":@"這是原生傳遞的參數(shù)"}};
    
    RCTRootView * rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                         moduleName:@"iOSRN-"
                                                  initialProperties:params
                                                      launchOptions:nil];

解決方案:查看App.js中是否注冊正確

AppRegistry.registerComponent('iOSRN', () => App)
  1. React Native: Unexpected token ‘:’. Expected a ‘)’ or a ‘,’ after a parameter declaration
    image.png

解決方案:
https://github.com/babel/babel/issues/14139#issuecomment-1011836916

修改 babel.config.js

from:
module.exports = {
       presets: ['module:metro-react-native-babel-preset'],    
};

to:
module.exports = {
       presets: [['module:metro-react-native-babel-preset', {
            unstable_disableES6Transforms: true
        }]],
 };
finally run yarn start --reset-cache to restart app.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容