npm start ..在intellij中运行正常,但在终端没有?

时间:2018-01-24 13:43:03

标签: javascript node.js intellij-idea ecmascript-6

npm start在intellij的终端中正常工作。

但是在常规shell终端

中运行时,它在下面的行失败了
 const {
   choosePort,
   createCompiler,
   prepareProxy,
   prepareUrls,
 } = require('react-dev-utils/WebpackDevServerUtils');

上面的代码位于start.js内,npm start运行node start.js

我猜intellij默认使用es6 我怎样才能在intellij之外模仿?

以下是错误

$ npm start

> bold-chat-admin@0.1.0 start /Users/eugenekim/Documents/boldchatting.web
> PORT=3000 node scripts/start.js

/Users/eugenekim/Documents/boldchatting.web/scripts/start.js:23
const {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:139:18)
    at node.js:999:3

npm ERR! Darwin 17.3.0
npm ERR! argv "/Users/eugenekim/.nvm/versions/node/v5.5.0/bin/node" "/Users/eugenekim/.nvm/versions/node/v5.5.0/bin/npm" "start"
npm ERR! node v5.5.0
npm ERR! npm  v3.3.12
npm ERR! code ELIFECYCLE
npm ERR! bold-chat-admin@0.1.0 start: `PORT=3000 node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bold-chat-admin@0.1.0 start script 'PORT=3000 node scripts/start.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bold-chat-admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     PORT=3000 node scripts/start.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls bold-chat-admin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/eugenekim/Documents/boldchatting.web/npm-debug.log

1 个答案:

答案 0 :(得分:0)

IDEA本身不会运行代码 - 它是使用您在 NPM 运行配置中选择的Node.js解释器运行的(通常与Preferences | Languages & Frameworks | Node.js and NPM中设置的相同,除非您选择一个明确的另一个)。 看起来用于在IDEA中运行脚本的Node.js解释器本身支持ES6解构,而终端中使用的节点5.5则不支持。有关不同节点版本支持的ES6技能的信息,请参阅http://node.green/