当前位置: 代码迷 >> 综合 >> React Native 坑之init 失败 react-native init ReactTest (SyntaxError: Unexpected identifier)
  详细解决方案

React Native 坑之init 失败 react-native init ReactTest (SyntaxError: Unexpected identifier)

热度:80   发布时间:2023-10-25 00:54:59.0

问题:在新建一个React native项目时,会创建不成功,详情见下面

当我们输入了创建项目的命令时

react-native init ReactTest

按理说应当成功,但实际却是这样的。。。

C:\Users\Zeking\Desktop\Code\Code\node_modules\react-native\local-cli\cliEntry.js:30
import type {
    CommandT} from './commands';^^^^SyntaxError: Unexpected identifierat new Script (vm.js:74:7)at createScript (vm.js:246:10)at Object.runInThisContext (vm.js:298:10)at Module._compile (internal/modules/cjs/loader.js:657:28)at Module._compile (C:\Users\Zeking\Desktop\Code\Code\node_modules\pirates\lib\index.js:91:24)at Module._extensions..js (internal/modules/cjs/loader.js:700:10)at Object.newLoader [as .js] (C:\Users\Zeking\Desktop\Code\Code\node_modules\pirates\lib\index.js:96:7)at Module.load (internal/modules/cjs/loader.js:599:32)at tryModuleLoad (internal/modules/cjs/loader.js:538:12)at Function.Module._load (internal/modules/cjs/loader.js:530:3)

后来发现这个是react native 0.6的 bug,我们只需要把版本号修改一下就可以了,具体这样做

react-native init {proj_name} –version react-native@0.55.4

这里面的{proj_name} 是具体的项目名称,例如我们上面的ReactTest,那就是:

react-native init ReactTest –version react-native@0.55.4

ok,到这里问题搞定!

  相关解决方案