美文网首页
React Native 安装步骤和常见问题

React Native 安装步骤和常见问题

作者: maisie0731 | 来源:发表于2016-03-07 14:22 被阅读2105次

    React Native安装步骤

    前期准备

    1. 安装nvm
    2. $ nvm install node && nvm alias default node
    • 安装watchman
      facebook的开源项目,用来监视文件并记录文件的改动情况
      $ brew install watchman
    • 安装flow
      $ brew install flow

    安装react native

    • 敲入命令行
      $ npm install -g react-native-cli
    • 选择路径创建工程:
      $ react-native init AwesomeProject
      这段时间会比较长,需要下载一些初始化文件
    • 运行:
      Android:$ react-native run-android

    Q&A

    1. 启动node server报错

    Failed to build DependencyGraph: Cannot read property 'root' of nullTypeError: Cannot read property 'root' of null at index.js:16:60
    at tryCallOne (/Users/liying/react_test/node_modules/react-native/node_modules/promise/lib/core.js:37:12)
    at /Users/liying/react_test/node_modules/react-native/node_modules/promise/lib/core.js:123:15
    at flush (/Users/liying/react_test/node_modules/react-native/node_modules/promise/node_modules/asap/raw.js:50:29)
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)~
    Process terminated. Press <enter> to close the window

    解决方案:

    1. $ brew update
    2. $ brew upgrade watchman
      如果在此过程中遇到报错:

    Error: The /usr/local directory is not writable.
    Even if this directory was writable when you installed Homebrew, other
    software may change permissions on this directory. Some versions of the
    "InstantOn" component of Airfoil are known to do this.

    You should probably change the ownership and permissions of /usr/local
    back to your user account.
    sudo chown -R $(whoami):admin /usr/local

    则输入:*$ sudo chown -R liying:admin /usr/local *

    2. 模拟器运行报错

    ReferenceError-Can-t-find-variable-fbBatchedBridge

    可能原因:模拟器与js服务器不在同一网段,无法访问服务器。
    解决办法:打开模拟器中的settings,wifi设置中选择WiredSSID链接。
    如果在真机上,摇一摇调出设置menu,选择Dev Setting,选择Debug server host & port for device,确保真机与电脑在同一网段,输入电脑IP+服务器默认端口号(8081) eg. 10.180.141.23:8081

    相关文章

      网友评论

          本文标题:React Native 安装步骤和常见问题

          本文链接:https://www.haomeiwen.com/subject/vyiakttx.html