【问题标题】:Node js express validator throwing error [duplicate]Node js express验证器抛出错误[重复]
【发布时间】:2018-06-04 16:33:35
【问题描述】:

我已经安装了 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

【问题讨论】:

  • 您使用的是哪个版本的节点?
  • 您的节点版本太旧,无法使用对象解构。更新。

标签: node.js express npm express-validator


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-14
      • 2021-01-31
      • 2015-11-05
      • 1970-01-01
      相关资源
      最近更新 更多