Installed 'ejs' package, but it isn't being found

884 views
Skip to first unread message

Vance

unread,
Sep 5, 2011, 6:15:00 PM9/5/11
to nodejs
I'm using node version 0.4.7, and npm version 1.0.27. I installed ejs
but when I try to run an app that require-s it, I get the following
error message/stack trace:


$ node app-express.js

node.js:134
throw e; // process.nextTick error, or 'error' event on first
tick
^
Error: Cannot find module 'ejs'
at Function._resolveFilename (module.js:320:11)
at Function._load (module.js:266:25)
at require (module.js:348:19)
at Object.<anonymous> (/home/vance/node-v0.4.7/chap04/app-
express.js:8:23)
at Module._compile (module.js:404:26)
at Object..js (module.js:410:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at Array.<anonymous> (module.js:423:10)
at EventEmitter._tickCallback (node.js:126:26)

Here's the beginning of the 'app-express.js' script (located in the
'chap04' subdirectory of my node install directory):


var htutil = require('./htutil');
var math = require('./math');
var express = require('express');
var app = express.createServer(
express.logger()
);

app.register('.html', require('ejs'));
// Optional since express defaults to CWD/views
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

Warren Henning

unread,
Sep 5, 2011, 9:19:07 PM9/5/11
to nod...@googlegroups.com
What happens when you type npm list in the project directory?

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

Nicolas Chambrier

unread,
Sep 6, 2011, 2:18:36 AM9/6/11
to nod...@googlegroups.com

I would bet you installed it globally. Protip: forget the "-g" option of npm :-)

Romain

unread,
Sep 6, 2011, 3:35:55 AM9/6/11
to nod...@googlegroups.com
Do a : 

    cd ~
    npm install ejs

Or a 

    sudo npm install -g ejs

It works for me.

2011/9/6 Nicolas Chambrier <nah...@gmail.com>

Nicolas Chambrier

unread,
Sep 6, 2011, 4:06:35 AM9/6/11
to nod...@googlegroups.com
No, this is absolutely not the way to go, definitely :)

How it works:
 * when looking for a module, node will search in "node_modules" folder (and will look for it in parent folder, going up until it finds a "node_modules" folder).
 * when you "npm install module" it will install the module in current folder's "node_modules" (it will try to find an existing one, or will search in parent folders etc... or create it).
Therefore, "npm install" and "require" work hand by hand, happily together.
It has also many more advantages, like making you able to use different versions of libraries in your different projects.

How it doesn't work:
 * when you "npm install -g module", the module is installed somewhere in a system folder.
 * when you will "require(module)" it will not find it, unless you tell node what this system folder is.
It also has many more disadvantages, like... you know :)

Easy way: "npm install module"
Sucky way: "npm install -g module"

Why the fuck people do global installs ? For the binaries! Even expressjs recommands a global install so you can call "express" binary. That's a baaaaad advice!
Simply do this: add "./node_modules/.bin" to your $PATH.
Then you can "npm install express" and... tadaaaa! call directly "express" (which will be found in ./node_modules/.bin/express, as locally installed) which will work without requiring any global install.


Honestly, I can't find any good reason to make global install. Oh yes, you can save some disk-space ? redis+contracts+ejs+express+tab+vows = 4M. You *can* duplicate this, even on your little SSD :)
si ce message est crypté:
- PGP KeyID -> 0x2F080247
- ou http://naholyr.free.fr/naholyr.pubring.gpg
Reply all
Reply to author
Forward
0 new messages