简体   繁体   English

无法在模拟器中启动React-Native应用

[英]Unable to start a react-native app in simulator

I am trying to follow the official react-native tutorial . 我正在尝试遵循官方的本机响应教程 Everything goes fine until I try to run the project. 一切正常,直到我尝试运行该项目。 A bash script then pops up with the following error message 然后,bash脚本弹出并显示以下错误消息

~/react_sites/AwesomeProject/node_modules/react-native/packager ~

/Users/Chris/react_sites/AwesomeProject/node_modules/react-native/local-cli/cli.js:74
  const setupEnvScript = /^win/.test(process.platform)
  ^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
~
Process terminated. Press <enter> to close the window

and the simulator gives a Could not connect to development server error. 并且模拟器给出“ Could not connect to development server错误。 How do I fix this? 我该如何解决?

I am using Xcode 7.2. 我正在使用Xcode 7.2。

I'm going to assume you have the pre-requisites , but double check before moving on. 我将假设您具有先决条件 ,但在继续之前请仔细检查。 Homebrew, Watchman, Node 4+, and Flow (optional). Homebrew,Watchman,Node 4+和Flow(可选)。

When you open the project in Xcode and push build button (play?), it should start the packager server automatically. 当您在Xcode中打开项目并按build(播放)按钮时,它应自动启动打包程序服务器。 But in your case, it doesn't seem to have. 但就您而言,它似乎没有。 In that case, try running npm start in the terminal from your project's root before building the project. 在这种情况下,尝试在终端中从项目的根目录运行npm start ,然后再构建项目。

I suppose you're using older version of node.js, you should install node.js 4.0 or higher. 我想您正在使用旧版本的node.js,则应安装node.js 4.0或更高版本。

please refer to https://facebook.github.io/react-native/docs/getting-started.html 请参考https://facebook.github.io/react-native/docs/getting-started.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM