![](/img/trans.png)
[英]I am trying to run node.js, how do I resolve "Cannot find module" error?
[英]how to resolve can not find module in node js
我的项目在台式机上。 我已经删除了node_modules文件夹并重新安装。 但这是行不通的。 请帮我解决。 我已经尝试了其他方法来处理堆栈溢出问题,但是它们对我不起作用,我不知道这是怎么回事。 请为我的最终项目提供帮助。 我的文件夹设置:
Ols
+--app.js
+--package.json
+--package-lock.json
+--views
+--allejs
+--public
+--cs
+---images
+node_modules
var express = require("express"); var app = express(); var bodyParser = require("body-parser"); app.use(express.static("public")); mongoose.connect("mongodb://localhost/ols"); app.use(bodyParser.urlencoded({extended: true})); app.set("view engine", "ejs"); app.get("/", function(req, res) { res.render("ols"); }); app.get("/home", function(req, res) { res.render("ols"); }); app.get("/alLlaptops", function(req, res) { res.render("allLaptops"); }); app.get("/contact", function(req, res) { res.render("contact"); }); app.get("/signup", function(req, res) { res.render("signup"); }); app.get("/login", function(req, res) { res.render("login"); }); app.get("/addtocart", function(req, res) { res.render("addtocart"); }); app.listen(3000, function() { console.log("Server is listening!!!"); });
module.js:538
throw err;
^
Error: Cannot find module 'C:\Users\Haider Ali\Desktop\OLS\OLS\views\app.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
检查您的package.json
文件。 看来您的app.js
和package.json
不在同一个文件夹中。
{
"name": "final-project",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js" // <--- node can't find app.js file
},
"keywords": [],
"author": "",
"license": "ISC"
}
您必须将其更改为:
"scripts": {
"start": "./views/app.js" // or wherever app.js file is
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.