2

react-native init AwesomeProject正在投掷SyntaxError: Unexpected token :,我不知道为什么。我已经卸载并重新安装了 react-native-cli。尝试有无yarn. 有什么建议么?

mes-MBP:myproject me$ react-native init AwesomeProject
This will walk you through creating a new React Native project in /Users/me/WebstormProjects/myproject/AwesomeProject
Using yarn v0.17.10
Installing react-native...
/Users/me/WebstormProjects/myproject/AwesomeProject/node_modules/react-native/local-cli/util/Config.js:43
  cwd: string,
     ^

SyntaxError: Unexpected token :
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at loader (/Users/me/WebstormProjects/myproject/AwesomeProject/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/me/WebstormProjects/myproject/AwesomeProject/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/me/WebstormProjects/myproject/AwesomeProject/node_modules/react-native/local-cli/cliEntry.js:13:16)
    at Module._compile (module.js:413:34)
4

3 回答 3

2

看起来像更新发布到的错误react-native。其他人也遇到同样的问题,所以我要回答这个问题并说这是一个包问题。https://github.com/facebook/react-native/issues/11384


在此问题得到解决之前,您可以使用rninit( https://www.npmjs.com/package/rninit ) 使用以前版本的react-native. 这对我有用:
rninit init mobile --source react-native@0.39.0

于 2016-12-09T02:43:17.103 回答
0

更新操作系统上的节点版本。

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
于 2017-07-26T22:20:02.623 回答
0

显然新版本的 React Native0.56.0有这个问题。

要解决此问题,您可以安装以前的版本。

react-native init --version="0.55.0" MyNewApp
于 2018-07-17T15:23:34.270 回答