【问题标题】:nodemon show error for es16es16的nodemon显示错误
【发布时间】:2017-07-17 05:26:25
【问题描述】:

我有Ubuntu 16.10node.js 7

nodejs -v
v7.6.0

我已经安装了sudo npm install supervisor -g 用于自动重新加载node.js。但是如果我写例如箭头函数,那么我会看到错误:

user@user-pc:~/dev/a$ nodemon  app.js
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
/home/user/dev/a/app.js:11
app.get('/rtc', (req, res)=>{
                          ^^
SyntaxError: Unexpected token =>
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
[nodemon] app crashed - waiting for file changes before starting...

如果我简单地运行我的应用程序nodejs app.js 那么一切都很好。

【问题讨论】:

    标签: javascript node.js node-modules nodemon


    【解决方案1】:

    看来,nodejs 使用的是 ES6/E2015 而 nodemon 没有。 结合babel-installation的提示,我建议nodemon --exec nodejs试用...

    【讨论】:

      【解决方案2】:

      Nodemon 使用 node 执行。

      请记住,nodemon 是 node 的替代包装,当您运行脚本时,可以将其视为在命令行中替换单词“node”。

      您需要使用 node 而不是 nodejs

      为节点创建符号链接

      sudo ln -s /usr/bin/nodejs /usr/local/bin/node
      

      【讨论】:

      • 这太危险了,更改/覆盖链接。可能会有副作用。
      • 如果您的系统中没有 node 是安全的。
      • 但在这种情况下,@alex10 可能安装了两个节点。
      猜你喜欢
      • 2019-11-13
      • 2021-09-18
      • 1970-01-01
      • 2014-02-13
      • 2021-06-06
      • 1970-01-01
      • 2013-12-04
      • 2019-03-26
      • 2016-02-23
      相关资源
      最近更新 更多