SyntaxError: Unexpected token ... in node_modules/express-validator/lib/express_validator.js:75

SyntaxError: Unexpected token ... in node_modules/express-validator/lib/express_validator.js:75

我正在尝试 运行 我的项目与节点 server.js 并且出现以下错误。

/Library/WebServer/Documents/PROJECT/node_modules/express-validator/lib/express_validator.js:75
        chain[name] = (...options) => {
                       ^^^

SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Library/WebServer/Documents/PROJECT/node_modules/express-validator/index.js:1:80)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

我正在使用 Express.js 框架。我上次做的时候还好好的。

经过大量搜索后,我终于发现我的一个项目是使用旧版本的 nodejs 构建的,我使用的是 node@4.4.7 并且在我的本地计算机上更改节点版本后,如下所示:

nvm ls   // to check out what versions of Node.js are installed on your machine

->       v4.4.7
         v8.9.1
         system
default -> 4.4.7 (-> v4.4.7)

要将 Node.js 从 node@4.4.7 切换到 node@8.9.1,我使用了以下命令:

nvm use v8.9.1

为了验证,我再次检查 nvm ls,现在它显示了。

    v4.4.7
->       v8.9.1
         system
default -> 4.4.7 (-> v4.4.7)

是的,ES6 中可用的扩展运算符将在节点 8 的版本 8 及更高版本中可用。