【问题标题】:npm start .. works fine in intellij but not in terminal?npm start .. 在 intellij 中可以正常工作,但在终端中不行?
【发布时间】:2018-01-24 13:43:03
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-06-29
    • 1970-01-01
    • 2022-01-07
    • 2021-05-07
    • 1970-01-01
    • 2023-03-10
    • 2020-03-23
    • 2022-06-13
    • 1970-01-01
    相关资源
    最近更新 更多