javascript - 找不到模块(错误 : Cannot find module './models/campground' )

标签 javascript node.js express mongoose

这是我的代码

var express     = require("express"),
app         = express(),
bodyParser  = require("body-parser"),
mongoose    = require("mongoose"),
Campground  = require("./models/campground"),
Comment     = require("./models/comment"),
seedDB      = require("./seeds")

this are my file's tree 当我运行上面的代码时,我收到此错误, 错误:找不到模块“./models/campground” 需要堆栈:

 - /workspace/webDevBootcamp/yelpcamp/v4/app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/workspace/webDevBootcamp/yelpcamp/v4/app.js:5:19)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/workspace/webDevBootcamp/yelpcamp/v4/app.js' ]
}

最佳答案

替换

Campground  = require("./models/campground"),

Campground  = require("./models/campgorund"),

或者将文件名“campgorund.js”更改为“campground.js”。 :)

关于javascript - 找不到模块(错误 : Cannot find module './models/campground' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61114337/

相关文章:

node.js - 如何在 Node ExpressJS 中的 get 请求上返回随机数据?

node.js - RedisStore - 类型错误 : Cannot read property 'prototype' of undefined

javascript - 如何延迟加载 Norton Secure Site Seal?

javascript - Shiny 的自定义输出

node.js - 是否可以仅在尚未安装 npm 包的情况下安装它?

node.js - 并行多次调用 lambda 似乎是在 50 个并发批处理中执行,而不是使用更高指定的保留并发数

node.js - 如何防止用户上传文件并消耗带宽?

javascript - 每次使用 jQuery,scrollTop() 返回零

javascript - 何时调用 XMLHttpRequest?

node.js - 从多页面应用程序进行身份验证后,如何在初始下载期间将 JWT token 加载到 React?