0

我已经安装了 express 验证器,但抛出错误如下:

express-validator@5.2.0

shopping-cart@0.0.0 开始 /var/www/nodejs/shopping-cart 节点 ./bin/www

/var/www/nodejs/shopping-cart/node_modules/express-validator/lib/express_validator.js:4
const { checkSchema, validationResult } = require('../check');
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/var/www/nodejs/shopping-cart/node_modules/express-validator/index.js:1:80)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

npm ERR! Linux 4.13.0-43-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/local/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! shopping-cart@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the shopping-cart@0.0.0 start script 'node ./bin/www'.
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 shopping-cart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs shopping-cart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls shopping-cart
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/nodejs/shopping-cart/npm-debug.log
4

2 回答 2

0

对象解构语法来自 ES6/ECMAScript 2015。

最新版本的 Node.js 6.x 支持 93% 的 ES6 功能。

于 2018-06-04T08:33:35.873 回答
0

此语法来自 ES6,节点版本 4 不支持。请更新 node.js 版本,推荐更新,因为 node 4 维护期结束。

于 2018-06-04T08:31:45.023 回答