Error: Cannot find module 'ejs'


Here is my complete error:

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/
    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.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'

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 got using npm install ejs. enter image description here so my question is.. what gives? What am I doing wrong so that node can't find EJS when I clearly have it installed?


10/13/2011 1:24:58 PM

Accepted Answer

I had this exact same problem a couple of days ago and couldn't figure it out. Haven't managed to fix the problem properly but this works as a temporary fix:

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

10/13/2011 2:37:17 PM

Install express locally

(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.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow