React Native 遇到的坑(持续更新)

  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 
//重新打开一个终端窗口
#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":@"这是原生传递的参数"}};
    
    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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容