找不到模块“ mongoose-unique-validator”

时间:2019-12-27 14:57:22

标签: javascript node.js mongodb express mongoose

我正在尝试使用护照身份验证创建待办事项列表应用程序,但是在运行节点应用程序时出现此错误:

module.js:549
    throw err;
    ^

Error: Cannot find module 'mongoose-unique-validator'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/walid/Todo list API/models/user.js:2:23)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/walid/Todo list API/app.js:7:12)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)

这是我的App文件,错误提示它无法连接到猫鼬:

const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser'); 
const expressValidator = require('express-validator');
const flash = require('connect-flash');
const session = require('express-session');
const config = require('./config/database');
const passport = require('passport');

mongoose.connect(config.database);
let db = mongoose.connection;

// Check connection
db.once('open', function () {
    console.log('Connected to mongoDB');
});

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

猫鼬库可能正在使用mongoose-unique-validator,通常他们将其安装在其内部package.json中,但看起来有些问题。尝试自己安装。

答案 1 :(得分:0)

错误中提到的模块mongoose-unique-validator是mongoose的子模块。安装猫鼬模块时,可能没有安装它。

您可以尝试通过键入以下命令之一来重新安装:

纱线

yarn add mongoose

NPM

npm install mongoose