Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 找不到模块(错误:找不到模块';/models/campground';)_Javascript_Node.js_Express_Mongoose - Fatal编程技术网

Javascript 找不到模块(错误:找不到模块';/models/campground';)

Javascript 找不到模块(错误:找不到模块';/models/campground';),javascript,node.js,express,mongoose,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 = requ

这是我的密码

var express     = require("express"),
app         = express(),
bodyParser  = require("body-parser"),
mongoose    = require("mongoose"),
Campground  = require("./models/campground"),
Comment     = require("./models/comment"),
seedDB      = require("./seeds")
当我运行上面的代码时,我得到了这个错误, 错误:找不到模块“./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' ]
}
-/workspace/webDevBootcamp/yelpcamp/v4/app.js
在Function.Module.\u解析文件名(internal/modules/cjs/loader.js:982:15)
at Function.Module._load(内部/modules/cjs/loader.js:864:27)
at Module.require(内部/modules/cjs/loader.js:1044:19)
根据需要(内部/modules/cjs/helpers.js:77:18)
反对。(/workspace/webDevBootcamp/yelpcamp/v4/app.js:5:19)
at模块编译(内部/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:1178:10)
at Module.load(内部/modules/cjs/loader.js:1002:32)
at Function.Module._load(内部/modules/cjs/loader.js:901:14)
在Function.executeUserEntryPoint[作为runMain](internal/modules/run_main.js:74:12)
在internal/main/run_main_module.js:18:47{
代码:“未找到模块”,
requireStack:['/workspace/webDevBootcamp/yelpcamp/v4/app.js']
}
更换

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

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

请解释这两个内联代码之间的区别。将Campground=require(“./models/Campground”)替换为Campground=require(“./models/campgorund”),在第一行中,它需要一个不存在的文件。“营地”。由于第二个文件名为“campgorund”,因此文件名已更正,问题在于您编写的文件名。在您提供的屏幕截图中,文件名为
Campgorund
,您尝试导入
campground
。没有其他问题。请修复此问题,您的代码将开始正常工作。:)
Campground  = require("./models/campgorund"),