“意外的令牌导入"创建新的 react-native 项目时出错 [英] "Unexpected token import" as error when creating new react-native project

查看:33
本文介绍了“意外的令牌导入"创建新的 react-native 项目时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个新的 react-native 项目:

I am creating a new react-native project using :

react-native init {proj_name}

但我收到以下错误.

D:\Reactnative\Project\{proj_name}\node_modules\react-native\local-cli\cliEntry.js:30
import type {CommandT} from './commands';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Module._compile (D:\Reactnative\Project\Learnwizz\node_modules\pirates\lib\index.js:91:24)
    at Module._extensions..js (module.js:654:10)
    at Object.newLoader [as .js] (D:\Reactnative\Project\Learnwizz\node_modules\pirates\lib\index.js:96:7)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)

推荐答案

这是在 Windows 上运行时 react-native 0.56 的一个已知错误(请参阅 这里这里a>).

This is a known bug right now with react-native 0.56 when running on Windows (see here and here).

在修复之前,您可以通过在运行 react-native init 时显式指定旧版本的 react-native 来解决此问题.例如

Until it is fixed, you can work around the issue by explicitly specifying an older version of react-native when running react-native init. E.g.

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

这篇关于“意外的令牌导入"创建新的 react-native 项目时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆