Error: cannot find module 'ejs'

Here is my complete mistake:

Error: Cannot find module 'ejs' at Function._resolveFilename (module.js:317:11) at Function._load (module.js:262:25) at require (module.js:346:19) at View.templateEngine (/Users/shamoon/local/node/lib/node_modules/express/lib/view/view.js:133:38) at Function.compile (/Users/shamoon/local/node/lib/node_modules/express/lib/view.js:65:17) at ServerResponse._render (/Users/shamoon/local/node/lib/node_modules/express/lib/view.js:414:18) at ServerResponse.render (/Users/shamoon/local/node/lib/node_modules/express/lib/view.js:315:17) at /Users/shamoon/Sites/soldhere.in/app.js:26:7 at callbacks (/Users/shamoon/local/node/lib/node_modules/express/lib/router/index.js:272:11) at param (/Users/shamoon/local/node/lib/node_modules/express/lib/router/index.js:246:11) 

My source code is also very simple:

 var express = require('express'); var app = module.exports = express.createServer(); // Configuration app.configure(function(){ app.use(express.bodyParser()); app.use(app.router); app.use(express.static(__dirname + '/public')); }); app.set('view engine', 'ejs'); app.set('view options', { layout: false }); app.get('/', function(req, res) { res.render('index', { message : 'De groeten' }); }); app.listen(3000); console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); 

In my folder, I have ejs installed in node_modules, which I used npm install ejs . enter image description here so my question is .. what gives? What am I doing wrong so that node cannot find EJS when I explicitly installed it?

thank

+70
express ejs
Oct 13 '11 at 13:24
source share
19 answers

I had the same problem a couple of days ago and I could not understand. Failed to fix the problem correctly, but it works as a temporary fix:

Go up one level (above app.js) and run npm install ejs . It will create a new node_modules folder, and Express should find the module then.

+120
Oct 13 '11 at 2:37 a.m.
source share

Install Express Locally

( npm install express in the project root directory)




Your project depends on both express and ejs , so you should specify them as dependencies in your package.json .

Thus, when you run npm install in the project directory, it will install both express and ejs , so var express = require('express') will be the local installation of express (which knows about the ejs module that you installed locally), not global, but itโ€™s not.

In general, it is recommended that you clearly list all the dependencies in your package.json , although some of them can already be installed globally, so you do not have such problems.

+19
Mar 14 '13 at 6:39
source share

I had the same problem. As soon as I set the NODE_PATH environment variable to the location of my modules (/ usr / local / node -v0.8.4 / node_modules in my case) the problem disappeared. The NODE_PATH postscript accepts a colon-separated list of directories if you need to specify more than one.

+8
Aug 20 '12 at 20:19
source share

In my case, I just added ejs manually in package.json :

  { "name": "myApp" "dependencies": { "express": "^4.12.2", "ejs": "^1.0.0" } } 

And run npm install (maybe you need to run it using sudo ) Note that ejs looks like the default by default.

+6
Mar 05 '15 at 18:38
source share

I installed ejs using the npm install ejs at the express directory level and this solved my problem.

I have an express function using the steps mentioned in the express guide http://expressjs.com/guide.html

+4
Jan 17 '14 at 11:33
source share

Install it locally, and install it globally. Then your project can run on any machine without any errors. I think this is better.

 npm install express --save npm install ejs --save 
+4
Oct. 15 '17 at 16:22
source share

I installed both: express and ejs with the --save option:

npm install express --save npm install express --save

This expression method and ejs depend on the package.json file.

+3
Dec 18 '15 at 0:38
source share

Reinstalling npm, express and ejs fixed my problem

This one worked for me

  1. On your terminal or cmd โ†’ Go to the application directory,
  2. cd pathtoyourapp / AppName
  3. restart your 'npm install'
  4. restart your 'npm install express'
  5. restart your 'npm install ejs'

after that the error has been fixed.

+3
Jan 10 '18 at 6:45
source share

I had this problem. I debugged the use of the node inspector and saw that from the node_modules folder where the express source files were, ejs was not installed. So I installed it there, and it worked.

npm install -g ejs did not put it where I expected it, even though NODE_PATH is installed in the same node_modules folder. Trying to do it wrong, just started with node.

+2
Mar 06 '13 at 23:23
source share

STEP 1

See npm ls | grep ejs npm ls | grep ejs at the root level of your project to check if you have added dependency to your ejs project.

If not, add it as dependencies in your project. (I prefer to add a dependency on package.json instead of the npm install 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 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 
+2
Oct 13 '16 at 4:52
source share

Add the dependency to package.json and then run npm install

  { ... ... "dependencies": { "express": "*", "ejs": "*", } } 
+2
Jun 12 '18 at 11:34
source share

I think the ejs template engine is not installed correctly on your computer. You just install the template engine using npm

 npm install ejs --save 

then include the following code in app.js

 app.set('view engine', 'ejs') 
+2
Jun 28 '18 at 13:32
source share

After you installed Express V xxx, you need to choose a template presentation engine. There are many really easy to learn. My personal wish is EJS .

Other really good and easy to learn can be:

To install EJS (and fix your mistake), run in the root of your project:

 npm install ejs 

Or if you use yarn:

 yarn add ejs 

Then you need a module, so open the file where you need the express (usually app.js or server.js).

add below var express = require('express');

 var ejs = require('ejs'); 
+2
Aug 17 '18 at 9:03
source share

I have the same problem as after installing express in my project directory. I previously installed it in the global scope with the -g option with the npm install command.

+1
Jun 07 '15 at 14:47
source share

In my case, it was a stupid mistake - it was a typo in the middleware. I wrote app.set('view engine', 'ejs.'); , the point caused an error. I installed ajs and bought locally

+1
Sep 09 '16 at 11:51 on
source share

In my case, there was no stupid syntax error, but the same error occurred. I have installed ejs and ejs-mate all over the world. I installed it locally and found that my error has been resolved.

+1
Apr 16 '17 at 19:34 on
source share

kindly make sure your dependencies in package.json files are updated. Try reinstalling them one at a time, and make sure your NPM is the latest version (current). It worked for me. I advise you to run npm install for packages (this is what worked in my own case after it refused to work, because I added the dependencies manually).

+1
02 Sep '17 at 0:26
source share
 app.set('view engine', 'ejs') 

and then in the terminal

 npm install ejs --save 

fixes the problem

0
Feb 21 '17 at 22:37
source share

Once upon a time, when the same problem happened to me.

The dependency was for ejs in the JSON file, tried to install it locally and globally, but did not work.

Then I added the module manually:

 app.set('view engine','ejs'); app.engine('ejs', require('ejs').__express); 

Then it works.

0
Jul 11 '19 at 12:16
source share



All Articles