nodemon 显示 es16 错误

nodemon show error for es16

我有 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 那么一切都很好。

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

Nodemon 使用 node exec.

Remember that nodemon is a replacement wrapper for node, think of it as replacing the word "node" on the command line when you run your script.

你需要使用 node 而不是 nodejs.

为节点

创建符号link
sudo ln -s /usr/bin/nodejs /usr/local/bin/node