最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Cannot find module 'expressValidator' - Stack Overflow

matteradmin8PV0评论

Below is a strange error when I try to use expressValidator module in nodejs.

Error: Cannot find module 'expressValidator'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\wamp\www\learning\nodejs_udemy\node_auth\app.js:5:
24)

Any mistake I made in my app.js?

var expressValidator = require('expressValidator');

// validator
app.use(expressValidator({
  errorFormatter: function(param, msg, value) {
      var namespace = param.split('.')
      , root    = namespace.shift()
      , formParam = root;

    while(namespace.length) {
      formParam += '[' + namespace.shift() + ']';
    }
    return {
      param : formParam,
      msg   : msg,
      value : value
    };
  }
}));

I follow the github usage guide but I still got an error.

Below is a strange error when I try to use expressValidator module in nodejs.

Error: Cannot find module 'expressValidator'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\wamp\www\learning\nodejs_udemy\node_auth\app.js:5:
24)

Any mistake I made in my app.js?

var expressValidator = require('expressValidator');

// validator
app.use(expressValidator({
  errorFormatter: function(param, msg, value) {
      var namespace = param.split('.')
      , root    = namespace.shift()
      , formParam = root;

    while(namespace.length) {
      formParam += '[' + namespace.shift() + ']';
    }
    return {
      param : formParam,
      msg   : msg,
      value : value
    };
  }
}));

I follow the github usage guide but I still got an error.

Share Improve this question asked Oct 4, 2015 at 12:54 Alice XuAlice Xu 5431 gold badge6 silver badges20 bronze badges 1
  • And you have actually installed that? – Roope Commented Oct 4, 2015 at 12:56
Add a ment  | 

2 Answers 2

Reset to default 2

npm modules can't have uppercase letters, the module is called express-validator, not expressValidator. As stated in express-validator's documentation, do:

var expressValidator = require('express-validator');

make sure to

npm i --save express-validator

before you try to use it.

I have similar issue. On my case I did a pull request from git and didn't install all latest packages.

yarn install 

OR

npm install

Post a comment

comment list (0)

  1. No comments so far