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

在尝试使用react-native init创建新项目时遇到错误:SyntaxError: Unexpected identifier。这是由于react-native 0.6版本的bug导致。解决方案是修改版本号,通过运行特定命令修复初始化问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:在新建一个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 identifier
    at 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,到这里问题搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值