My question is about the SyntaxError, I'm getting after installing latest version of mongoose-validator. I have just installed the latest version of mongoose-validator(1.3 or 1.3.2) for a simple MEAN stack application. Whenever I start the node server, I'm getting an error, whereby the console sees 3 functions in the "mongoose-validator.js" file, and each of these functions has a parameter beginning with 3 dots('...param1'), which it says is unexpected. Removing the dots brings up some other errors. Also, I don't think it's appropriate to make any changes in node-modules. Starting the node server gives the following SyntaxError.
C:\mean_stack_app\node_modules\mongoose-validator\lib\mongoose-validator.js:14
const omit = function omit(obj, ...keys) {
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:405: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> (C:\mean_stack_app\app\models\user.js:5:16)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405: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> (C:\mean_stack_app\app\routes\api.js:1:74)
at Module._compile (module.js:398:26)
user.js:5:16
var mongoose = require('mongoose'); //import mongoose
var Schema = mongoose.Schema; //to use mongoose method Schema and store it in var Schema
var bcrypt = require('bcrypt-nodejs');
var titlize = require('mongoose-title-case');
var validate = require('mongoose-validator');
var nameValidator = [
validate({
validator: 'matches',
arguments: /^[a-zA-Z]+$/i
})
];
api.js:1:74
var User = require('../models/user');
var jwt = require('jsonwebtoken');
I have installed the following Dependencies in package.json file along with mongoose-validator:
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"express-session": "^1.15.5",
"jsonwebtoken": "^7.4.2",
"mongoose": "^4.11.4",
"mongoose-title-case": "0.0.4",
"mongoose-validator": "^1.3.2",
"morgan": "^1.8.2",
"passport": "^0.3.2",
"passport-facebook": "^2.1.1",
"passport-google-oauth": "^1.0.0",
"passport-twitter": "^1.0.4"
What should I do to fix this issue? Can someone please help me?
The Mongoose-Validator library is using the rest parameters syntax and it doesn't seem to be supported by your Node version. You need to use version 6.4 or higher. You can check by running node -v
in your command line.
I suggest using [NVM][1]
(Node Version Manager) to upgrade your node runtime.
If you're on Windows, there is a separate [NVM-Windows][1]
package.