我正在使用以下工具创建一个新的react native项目:

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的一个已知错误(请参阅herehere).

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

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

React-native相关问答推荐

如何在renderItem中显示每个项目的索引号,保持分页的前一个下一个按钮

FlatList 总是增长到 100% 高度

每当我在 React Native Tab Navigator 中切换标签时触发 UseEffect

任务:react-native-async-storage_async-storage:generateDebugRFile FAILED

应用程序主体尚未注册

如何在react-native 中存储/保存数据

为应用创建单个 MobX store 的最佳方式是什么?

React Native - 初始属性 Android

如何在获取请求中传递 POST 参数?

React-Native Packager 失败:重复的模块名称

在 UIManager 中找不到RNCSafeAreaView

更改默认的 React Native 下拉箭头图标

如何删除不需要的expo 模块

如何在 React Native 上获取设备的 ip?

React Native Android 文本组件额外填充

TypeError : props.navigation.getParam 不是函数. In(props.navigation.getParam('name')

更改按钮 colored颜色 onPress(切换功能)

如何在自定义组件上使用 onPress?

react-native图像预取

React Native 多行TextInput,文本居中