如何解决 React Native 入门指南中的挂起问题?
How do I troubleshoot a hang in React Native's Getting Started?
我正在使用 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
命令启动开发服务器并在终端上打印二维码,如说明所述。
我第一次尝试使用入门时收到了一些错误消息,您可以在下面找到这些消息。根据这些消息,我安装了 watchman 并再次尝试 npm start
。那一次,应用程序似乎启动了一个服务器。我没有看到二维码,但几秒钟后出现了一些错误消息,然后就什么也没有了。
这是 shell session 的样子。有些部分很长(数百行),我将它们排除在外。我已经包含了我发现的所有错误和警告。
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
我暂时搁置了内核建议,而是安装了watchman。
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 多分钟,没有进一步的输出。
当您使用 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。
我正在使用 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
命令启动开发服务器并在终端上打印二维码,如说明所述。
我第一次尝试使用入门时收到了一些错误消息,您可以在下面找到这些消息。根据这些消息,我安装了 watchman 并再次尝试 npm start
。那一次,应用程序似乎启动了一个服务器。我没有看到二维码,但几秒钟后出现了一些错误消息,然后就什么也没有了。
这是 shell session 的样子。有些部分很长(数百行),我将它们排除在外。我已经包含了我发现的所有错误和警告。
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
我暂时搁置了内核建议,而是安装了watchman。
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 多分钟,没有进一步的输出。
当您使用 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。