如何解决React Native的入门问题?

时间:2017-09-01 06:56:32

标签: node.js react-native watchman

我正在使用React Native Getting Started instructions。我正在使用带有macOS Sierra 10.12.6的2010 MacBook Pro。该计算机具有Node.js v8.4.0。

我是React Native的新手,也是React和Node的新手,所以我可能会遗漏一些基本的东西。我确实让React在同一台计算机上工作。我按照上面页面上的说明操作,希望看到npm start命令启动开发服务器并在终端上打印QR码,如说明所示。

我第一次尝试使用入门时收到了一些错误消息,您可以在下面找到。基于这些消息,我安装了watchman并再次尝试npm start。那个时候,应用似乎启动了服务器。我没有看到QR码,但几秒钟后出现了一些错误消息,然后什么都没有。

这是shell会话的样子。有些部分很长(数百行),我把它们留了下来。我已经包含了我发现的所有错误和警告。

bash-3.2$ create-react-native-app AwesomeProject # verbatim from the getting-started page
Creating a new React Native app in /Users/dvincent/Desktop/react-native-test/AwesomeProject.

Using package manager as npm with npm interface.
Installing packages. This might take a couple minutes.
Installing react-native-scripts...

[?25hAwesomeProject@0.1.0 /Users/dvincent/Desktop/react-native-test/AwesomeProject
`-- react-native-scripts@1.3.0 
  +-- @expo/bunyan@1.8.10 
  | +-- moment@2.18.1 

在这里,我遗漏了数百条看似不重要的行。这些似乎很重要:

    +-- uuid@3.1.0  deduped
    +-- xmldom@0.1.27 
    `-- yesno@0.0.1 

npm WARN react-redux@5.0.6 requires a peer of react@^0.14.0 || ^15.0.0-0 || ^16.0.0-0 but none was installed.
Installing dependencies using npm...

[?25hnpm WARN deprecated connect@2.30.2: connect 2.x series is deprecated
[?25h
> fsevents@1.1.2 install /Users/dvincent/Desktop/react-native-test/AwesomeProject/node_modules/fsevents
> node install

[fsevents] Success: "/Users/dvincent/Desktop/react-native-test/AwesomeProject/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
[?25hAwesomeProject@0.1.0 /Users/dvincent/Desktop/react-native-test/AwesomeProject
+-- expo@20.1.1 
| +-- @expo/vector-icons@5.2.0 
| | `-- react-native-vector-icons@4.1.1 
| |   `-- yargs@6.6.0  deduped
| +-- babel-preset-expo@3.0.0 
| | +-- babel-plugin-module-resolver@2.7.1 
| | | +-- find-babel-config@1.1.0 

在达到一些警告并看到成功之前,我省略了更多行!消息按预期。

|   +-- y18n@3.2.1 
|   `-- yargs-parser@4.2.1 
|     `-- camelcase@3.0.0  deduped
`-- react-test-renderer@16.0.0-alpha.12 

npm WARN react-native-gesture-handler@1.0.0-alpha.17 requires a peer of react@>= 16.0.0 but none was installed.
npm WARN react-native-branch@2.0.0-beta.3 requires a peer of react@>=15.4.0 but none was installed.
npm WARN lottie-react-native@1.1.1 requires a peer of react@>=15.3.1 but none was installed.


Success! Created AwesomeProject at /Users/dvincent/Desktop/react-native-test/AwesomeProject
Inside that directory, you can run several commands:

  npm start
    Starts the development server so you can open your app in the Expo
    app on your phone.

以下结尾。

We suggest that you begin by typing:

  cd AwesomeProject
  npm start

Happy hacking!

所以我继续这样做:

bash-3.2$ cd AwesomeProject/
bash-3.2$ npm start

> AwesomeProject@0.1.0 start /Users/dvincent/Desktop/react-native-test/AwesomeProject
> react-native-scripts start

1:59:58 PM: Unable to start server
See https://git.io/v5vcn for more information, either install watchman or run the following snippet:
  sudo sysctl -w kern.maxfiles=5242880
  sudo sysctl -w kern.maxfilesperproc=524288

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! AwesomeProject@0.1.0 start: `react-native-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the AwesomeProject@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/dvincent/.npm/_logs/2017-09-01T03_59_58_661Z-debug.log

我暂时搁置了内核建议,而是安装了守望者。

bash-3.2$ npm install watchman
[?25hAwesomeProject@0.1.0 /Users/dvincent/Desktop/react-native-test/AwesomeProject
`-- watchman@0.1.8 
  +-- cli@1.0.1 
  | +-- exit@0.1.2 
  | `-- glob@7.1.2 
  `-- eco@1.1.0-rc-3 
    +-- coffee-script@1.12.7 
    `-- strscan@1.0.1 

npm WARN lottie-react-native@1.1.1 requires a peer of react@>=15.3.1 but none was installed.
npm WARN react-native-branch@2.0.0-beta.3 requires a peer of react@>=15.4.0 but none was installed.
npm WARN react-native-gesture-handler@1.0.0-alpha.17 requires a peer of react@>= 16.0.0 but none was installed.

然后我尝试再次启动服务器。

bash-3.2$ npm start

> AwesomeProject@0.1.0 start /Users/dvincent/Desktop/react-native-test/AwesomeProject
> react-native-scripts start

2:29:06 PM: Starting packager...
***ERROR STARTING PACKAGER***
Starting React Native packager...
Scanning 767 folders for symlinks in /Users/dvincent/Desktop/react-native-test/AwesomeProject/node_modules (21ms)
Loading dependency graph.
Running packager on port 19001.


2017-09-01 14:29 node[22151] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
***ERROR STARTING PACKAGER***

2017-09-01 14:29 node[22151] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
***ERROR STARTING PACKAGER***

2017-09-01 14:29 node[22151] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)


此时我停止了等待 并抓住了shell的成绩单来开始这个问题。我在写这篇文章时离开了它,超过40分钟,没有进一步的输出。

1 个答案:

答案 0 :(得分:1)

当您使用npm安装watchman时,这看起来像一个已知问题。可以通过删除使用npm安装的watchman并使用homebrew安装它来修复它。

# Remove any existing binaries
rm -rf /usr/local/var/run/watchman/
# Remove any npm globally installed instances
npm uninstall watchman
# Nuke the last brew installed version
brew uninstall watchman
# Brew install and build latest
brew install watchman

有关详细信息,请参阅此issue