React-Native开发踩坑记录

2018-11-07  本文已影响0人  wesk痕

ReactNative 在 Visual Studio Code环境下报错

  1. error: bundling failed: TypeError: Cannot read property 'bindings' of null

    原因:package.json 中的"babel-preset-react-native” 版本过低,修改到”5.0.0"及以上

    解决方案:
    "babel-preset-react-native": "^5.0.0”

  2. error: bundling failed: Error: Unable to resolve module react-native-root-toast from /Users/weskhen/Documents/mst/RNDemo/app/components/Toast.js: Module react-native-root-toast does not exist in the Haste module map

    1.对应的moudle 确实不存在,需要手动添加
    2.查看moudle存在,访问路径错误

  1. Error while executing command 'react-native run-ios --simulator iPhone X --no-packager’

    ios目录下,没有xcode的工程文件

    //工程编译报错
    TypeError: Cannot read property '2' of null

  1. Module AppRegistry is not a registered callable module (calling runApplication)

    do
    npm run start --reset-cache
    or
    react-native start --reset-cache
    1. Clear watchman watches: `watchman watch-del-all`.
          2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
          3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  
          4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
    
  2. error Invalid tag name "^23ç.4.1": Tags may not have any characters that encodeURIComponent encodes.

    package.json文件出现错误!

iOS编译报错

  1. warning :Native component for “RCTImageView” does not exist

需要引入 RCTImage 模块解决
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'RCTImage']

Android编译报错

  1. unable to load script from assets ‘index.android bundle’

    第一步(创建缺失的目录):mkdir android\app\src\main\assets
    第二步(在创建好的目录添加程序需要的文件):react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
    第三步:react-native run-android

  1. 安卓模拟器不能联网
    cd到tools下
    wujian-2:platform-tools weskhencd /Users/weskhen/Documents/Android/android-sdk-macosx/tools wujian-2:tools weskhen ./emulator -list-avds
    Nexus_5X_API_27
    Pixel_XL_Edited_API_27
    wujian-2:tools weskhen$ cd /Users/weskhen/Documents/Android/android-sdk-macosx/emulator
    emulator @Pixel_XL_Edited_API_27 -dns-server 8.8.8.8,114.114.114.114
上一篇下一篇

猜你喜欢

热点阅读