搜尋

首頁  >  問答  >  主體

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

我是跟着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.<anonymous> (/Users/yiwang/Documents/react_native/AwesomeProject/node_modules/react-native/cli.js:15:18)
伊谢尔伦伊谢尔伦2863 天前600

全部回覆(2)我來回復

  • 巴扎黑

    巴扎黑2017-04-17 13:03:45

    升級node到4.1以上。

    回覆
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:03:45

    需要升級node,但是如果你使用的是nvm來管理node的版本的話。
    直接使用node use <不同版本>,如果你係統版本是低於react-native要求的版本的話,也會有問題。
    因為react-native在啟動時會開啟一個新窗口,如果你沒有在.xxx之類的設定檔配置的話,還是會有問題。

    1.建議使用nvm來管理node(很有可能處於某種原因不想放棄之前舊版本的node的專案);
    2.使用nvm alias default stable(這裡使用最新版作為預設版本,需要使用nvm install stable安裝最新版本)

    祝君好運!

    回覆
    0
  • 取消回覆