猫鼬已安装,但出现错误“找不到模块猫鼬”

时间:2019-04-23 20:11:25

标签: javascript node.js mongodb mongoose

我在我的Node.js项目中包含了猫鼬,但是当我启动服务器时,出现此错误:`错误:找不到模块'猫鼬'

Error: Cannot find module 'mongoose'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:611:15)
at Function.Module._load (internal/modules/cjs/loader.js:537:25)
at Module.require (internal/modules/cjs/loader.js:665:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/jaredmoats/Desktop/Web-Development/courses/full-stack-react/models/User.js:1:80)
at Module._compile (internal/modules/cjs/loader.js:736:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
at Function.Module._load (internal/modules/cjs/loader.js:560:3)
at Module.require (internal/modules/cjs/loader.js:665:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/jaredmoats/Desktop/Web-Development/courses/full-stack-react/server/index.js:5:1)
at Module._compile (internal/modules/cjs/loader.js:736:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
at Module.load (internal/modules/cjs/loader.js:628:32)

这使我感到困惑,因为我的猫鼬在几周前已成功完成了该项目。它突然决定不工作。

有人知道发生了什么吗?

编辑:

这是我的index.js。

const express = require("express");
const mongoose = require("mongoose");
const keys = require("./config/keys");
require("./services/passport");
require("../models/User");

mongoose.connect(keys.mongoURI);

console.log(keys.mongoURI);

//generate a new express application
const app = express();

//Call the exported function in authRoutes immediately after it's required.
require("./routes/authRoutes")(app);

//dyanamically figure out what port to listen to (for heroku)
const PORT = process.env.PORT || 5000;

//tell express to start listening on assigned port
app.listen(PORT);

非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试

rm -rf node_modules
npm install -g npm@latest
npm i core-util-is