node.js - React-native npm start启动报错!

 手机用户2502860713 发布于 2022-11-04 09:31

我是跟着RN官网的教程来玩的:
https://facebook.github.io/react-native/docs/getting-started.html#content
求解惑

启动时在终端看到的错误信息如下

/Users/yiwang/Documents/react_native/AwesomeProject/node_modules/react-native/local-cli/cli.js:56
const setupEnvScript = /^win/.test(process.platform)
^^^^^
SyntaxError: Use of const in strict mode.

at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/yiwang/Documents/react_native/AwesomeProject/node_modules/react-native/node_modules/babel-core/lib/api/register/node.js:214:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/Users/yiwang/Documents/react_native/AwesomeProject/node_modules/react-native/cli.js:15:18)
2 个回答
  • 需要升级node,但是如果你使用的是nvm来管理node的版本的话。
    直接使用node use <不同版本>,如果你系统版本是低于react-native要求的版本的话,也会有问题。
    因为react-native在启动时会开启一个新窗口,如果你没有在.xxx之类的配置文件配置的话,还是会有问题。

    1.建议使用nvm来管理node(很有可能处于某种原因不想放弃之前旧版本的node的项目);
    2.使用nvm alias default stable(这里使用最新版作为默认版本,需要使用nvm install stable安装最新版本)

    祝君好运!

    2022-11-07 16:04 回答
  • 升级node到4.1以上。

    2022-11-07 16:14 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有