`react-native init AwesomeProject` throwing Syntax

2020-04-18 06:16发布

react-native init AwesomeProject is throwing SyntaxError: Unexpected token : and I'm not sure why. I've uninstalled and re-installed react-native-cli. Tried with and without yarn. Any suggestions?

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)

3条回答
欢心
2楼-- · 2020-04-18 06:38

Looks like the error an update was published to react-native. Others are experiencing the same issue so I'm going to answer this and say it's a package issue. https://github.com/facebook/react-native/issues/11384


Until this gets resolved, you can use rninit(https://www.npmjs.com/package/rninit) to install using the previous version of react-native. This worked for me:
rninit init mobile --source react-native@0.39.0

查看更多
SAY GOODBYE
3楼-- · 2020-04-18 06:39

Update node version on OS.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
查看更多
Viruses.
4楼-- · 2020-04-18 07:05

Apparently the new version React Native 0.56.0 has this problem.

To fix this problem, you can install the previous version.

react-native init --version="0.55.0" MyNewApp
查看更多
登录 后发表回答