npm start命令我得到语法错误:在严格模式下使用const

时间:2016-03-26 14:21:03

标签: javascript reactjs npm ecmascript-6 babeljs

xxx-nameKumar - MacBook-Pro:MyApp xxx-name $ npm start

> @ start /Users/xxx-name/Desktop/FrontEnd/MyApp
> babel-node tools/run start

/Users/xxx-name/Desktop/FrontEnd/MyApp/tools/run.js:20
  const task = typeof fn.default === 'undefined' ? fn : fn.default;
  ^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at loader (/Users/xxx-name/Desktop/FrontEnd/MyApp/node_modules/babel-cli/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/xxx-name/Desktop/FrontEnd/MyApp/node_modules/babel-cli/node_modules/babel-register/lib/node.js:136:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at /Users/xxx-name/Desktop/FrontEnd/MyApp/node_modules/babel-cli/lib/_babel-node.js:161:27
    at Object.<anonymous> (/Users/xxx-name/Desktop/FrontEnd/MyApp/node_modules/babel-cli/lib/_babel-node.js:162:7)
    at Module._compile (module.js:460:26)

npm ERR! Darwin 14.5.0
npm ERR! argv "node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE
npm ERR! @ start: `babel-node tools/run start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ start script 'babel-node tools/run start'.
npm ERR! This is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel-node tools/run start
npm ERR! You can get their info via:
npm ERR!     npm owner ls 
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/xxx-name/Desktop/FrontEnd/MyApp/npm-debug.log

3 个答案:

答案 0 :(得分:1)

您有语法错误:

SyntaxError: Use of const in strict mode.

你有没有使用严格的&#39;你的代码?

您拥有什么版本的节点?

const和let是ES6的一部分,在Node.js 0.10或0.12中默认不启用。

答案 1 :(得分:1)

更新nodejs。 Const是一项新功能。您拥有的版本(0.12.0)已过时。该链接表示您需要5.0或​​更新版本。从https://nodejs.org/en/下载并安装5.9.1(而不是4.4.1)。然后再试一次。

答案 2 :(得分:-2)

您可以尝试输入

来更新您的npm
  

sudo Npm install -g npm