Here is my complete error:
Error: Cannot find module \'ejs\'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
STEP 1
See npm ls | grep ejs
at root level of your project to check if you have already added ejs
dependency
to your project.
If not, add it as dependencies
to your project. (I prefer adding dependency to package.json
instead of npm install
ing the module.)
eg.
{
"name": "musicpedia",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"jade": "~1.11.0",
"ejs": "^1.0.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
STEP 2 download the dependencies
npm install
STEP 3 check ejs module
$ npm ls | grep ejs
musicpedia@0.0.0 /Users/prayagupd/nodejs-fkers/musicpedia
├── ejs@1.0.0
(npm install express
while in the project's root directory)
Your project depends on both express
and ejs
, so you should list them both as dependencies in your package.json
.
That way when you run npm install
in you project directory, it'll install both express
and ejs
, so that var express = require('express')
will be the local installation of express (which knows about the ejs
module that you installed locally) rather than the global one, which doesn't.
In general it's a good idea to explicitly list all dependencies in your package.json
even though some of them might already be globally installed, so you don't have these types of issues.
npm i ejs --force
this worked for me
npm install ejs --save
worked for me ! ✅
On goormIDE, I had this file configuration :
In my main.js file, I also had this route
app.get("/", function(req, res){
res.render("home.ejs");
})
npm install ejs -g
didn't add the corresponding dependency within the package.json.
npm install ejs --save
did. I executed the command line from the container directory. Manually it could have been added into the package.json with :
**
"dependencies": {
"ejs": "^3.0.2",}
**
i had the same issue and tried a few of the given solutions but it still didn't work. all i did was to run the "npx yarn" command in the root folder of my project and that was it.
i had the same problem. So i did the following and it worked for me.
solution:
npm install ejs --save
npm install express --save
by doing so it creates the required dependencies in the package.json file