Error: Cannot find module 'express'

8,230 views
Skip to first unread message

Rohit Singh

unread,
Mar 3, 2011, 6:04:00 AM3/3/11
to Express
Hi, I installed npm and node as per the instructions given on the
github page of npm.

I can install npm packages normally, and i installed express by "npm
install express" command.
This is the app.js file am trying to run:

var app = require('express').createServer();

app.get('/', function(req, res){
res.send('hello world');
});

app.listen(3000);

This is the output:

:~/app$ node app.js

node.js:63
throw e;
^
Error: Cannot find module 'express'
at loadModule (node.js:275:15)
at require (node.js:411:14)
at Object.<anonymous> (/home/node/app/app.js:1:73)
at Module._compile (node.js:462:23)
at Module._loadScriptSync (node.js:469:10)
at Module.loadSync (node.js:338:12)
at Object.runMain (node.js:522:24)
at Array.<anonymous> (node.js:756:12)
at EventEmitter._tickCallback (node.js:55:22)
at node.js:773:9

VM is a Ubuntu 10.04.1 LTS 32 bit.

Rohit Singh

unread,
Mar 3, 2011, 6:40:53 AM3/3/11
to Express
oops, i reported it by mistake. sorry.
The error still persists, and I don't know what to do.

Laurie Harper

unread,
Mar 3, 2011, 9:56:56 PM3/3/11
to expre...@googlegroups.com
Which instructions did you follow? More particularly, which versions of Node and npm did you end up with? Judging by the format of the error report, it looks like you're using an old(er) version of Node; what are the results of:

node --version
npm --version
npm ls installed express
npm view express

L.

> --
> You received this message because you are subscribed to the Google Groups "Express" group.
> To post to this group, send email to expre...@googlegroups.com.
> To unsubscribe from this group, send email to express-js+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/express-js?hl=en.
>

--
Laurie Harper
http://laurie.holoweb.net/

Rohit Singh

unread,
Mar 4, 2011, 1:30:24 AM3/4/11
to Express
node -v
v0.2.5

npm -v
v0.2.18

express -v
1.0.8

npm view express
npm info it worked if it ends with ok
npm info using n...@0.2.18
npm info using no...@v0.2.5
{ name: 'express'
, description: 'Sinatra inspired web development framework'
, 'dist-tags': { latest: '2.0.0beta' }
, maintainers: 'tjholowaychuk <t...@vision-media.ca>'
, author: 'TJ Holowaychuk <t...@vision-media.ca>'
, time:
{ '0.14.0': '2010-12-29T19:38:25.450Z'
, '0.14.1': '2010-12-29T19:38:25.450Z'
, '1.0.0beta': '2010-12-29T19:38:25.450Z'
, '1.0.0beta2': '2010-12-29T19:38:25.450Z'
, '1.0.0rc': '2010-12-29T19:38:25.450Z'
, '1.0.0rc2': '2010-12-29T19:38:25.450Z'
, '1.0.0rc3': '2010-12-29T19:38:25.450Z'
, '1.0.0rc4': '2010-12-29T19:38:25.450Z'
, '1.0.0': '2010-12-29T19:38:25.450Z'
, '1.0.1': '2010-12-29T19:38:25.450Z'
, '1.0.2': '2011-01-11T02:09:30.004Z'
, '1.0.3': '2011-01-13T22:09:07.840Z'
, '1.0.4': '2011-02-05T19:13:15.043Z'
, '1.0.5': '2011-02-05T19:16:30.839Z'
, '1.0.6': '2011-02-07T21:45:32.271Z'
, '1.0.7': '2011-02-07T22:26:51.313Z'
, '1.0.8': '2011-03-02T02:58:14.314Z'
, '2.0.0beta': '2011-03-04T00:19:22.568Z'
}
, version: '2.0.0beta'
, contributors:
[ 'TJ Holowaychuk <t...@vision-media.ca>'
, 'Aaron Heckmann <aaron.heck...@gmail.com>'
, 'Ciaran Jessup <cia...@gmail.com>'
, 'Guillermo Rauch <rau...@gmail.com>'
]
, dependencies:
{ connect: '>= 1.0.1'
, mime: '>= 0.0.1'
, qs: '>= 0.0.6'
}
, keywords:
[ 'framework'
, 'sinatra'
, 'web'
, 'rest'
, 'restful'
]
, main: 'index'
, bin: { express: './bin/express' }
, engines: { node: '>= 0.4.1 < 0.5.0' }
, directories: { lib: './lib', bin: './bin' }
, files: ''
, dist:
{ shasum: 'c2095479887128f161ee13211e7b886edb4d9f98'
, tarball: 'http://registry.npmjs.org/express/-/
express-2.0.0beta.tgz'
}
}
npm ok

For now, express is working when am using it like :
var express = require('/home/node/local/lib/node/.npm/express/active/
package/lib/express');

Joshua Cohen

unread,
Mar 4, 2011, 10:03:40 AM3/4/11
to expre...@googlegroups.com
Try this:

node -e require.paths

That will print out the paths that Node looks when you require something. Check to see if express is installed in any of those directories, if not something has gone awry with your npm install.

Rohit Singh

unread,
Mar 4, 2011, 11:00:49 AM3/4/11
to Express
It can't be a npm problem, all other modules are detected well.
For eg, redis, mysql, socket.io, etc.
node -e require.paths returns:

undefined:1

^
ReferenceError: require is not defined
at eval at <anonymous> (node.js:762:36)
at eval (native)
at node.js:762:36


On Mar 4, 8:03 pm, Joshua Cohen <defea...@gmail.com> wrote:
> Try this:
>
> node -e require.paths
>
> That will print out the paths that Node looks when you require something.
> Check to see if express is installed in any of those directories, if not
> something has gone awry with your npm install.
>
> On Fri, Mar 4, 2011 at 12:30 AM, Rohit Singh <geek.rohit.si...@gmail.com>wrote:
>
>
>
>
>
>
>
> > node -v
> > v0.2.5
>
> > npm -v
> > v0.2.18
>
> > express -v
> > 1.0.8
>
> > npm view express
> > npm info it worked if it ends with ok
> > npm info using n...@0.2.18
> > npm info using n...@v0.2.5
> >   , 'Aaron Heckmann <aaron.heckmann+git...@gmail.com>'
> >   , 'Ciaran Jessup <ciar...@gmail.com>'

Luke Galea

unread,
Mar 4, 2011, 11:05:58 AM3/4/11
to expre...@googlegroups.com, Rohit Singh
This happened to us yesterday as well as we set up a new server. We
downgraded to 1.0.7 to get around it. Can't imagine what's up, but you
aren't alone Rohit.

Joshua Cohen

unread,
Mar 4, 2011, 11:09:49 AM3/4/11
to expre...@googlegroups.com
The problem could be that express did not get installed to the correct location by npm for some reason. Weird that require.paths doesn't work, it works for me under 0.4.x, don't think there should be any difference under 0.2.x though (someone correct me if I'm wrong though...).

I think the first step to figuring out what's going on is to track down where node is looking for for modules and see if express is actually there.

vision media [ Tj Holowaychuk ]

unread,
Mar 4, 2011, 11:54:32 AM3/4/11
to expre...@googlegroups.com
hmm... I think this is an npm version issue, maybe because im missing "main" in package.json, its tough to me to even test since npm breaks compatibility 
Tj Holowaychuk
Vision Media
President & Creative Lead

James Hughes

unread,
Mar 21, 2011, 5:14:28 PM3/21/11
to Express
Sorry to bump this but I've just hit the same issue on a new mac. Is
there workaround for it currently besides building and installing
Express manually?

On Mar 4, 4:54 pm, "vision media [ Tj Holowaychuk ]" <t...@vision-
media.ca> wrote:
> hmm... I think this is an npm version issue, maybe because im missing "main"
> in package.json, its tough to me to even test since npm breaks
> compatibility
>
>
>
>
>
>
>
>
>
> On Fri, Mar 4, 2011 at 8:09 AM, Joshua Cohen <defea...@gmail.com> wrote:
> > The problem could be that express did not get installed to the correct
> > location by npm for some reason. Weird that require.paths doesn't work, it
> > works for me under 0.4.x, don't think there should be any difference under
> > 0.2.x though (someone correct me if I'm wrong though...).
>
> > I think the first step to figuring out what's going on is to track down
> > where node is looking for for modules and see if express is actually there.
>

James Hughes

unread,
Mar 22, 2011, 5:54:17 AM3/22/11
to Express
Turns out that by upgrading to NPM 1.0RC this issue has been resolved.

// ravi

unread,
May 30, 2013, 11:31:50 AM5/30/13
to expre...@googlegroups.com
On May 24, 2013, at 6:44 AM, Pradeep RSC <prade...@gmail.com> wrote:
> On Thursday, 3 March 2011 16:34:00 UTC+5:30, Rohit Singh wrote:
>> Hi, I installed npm and node as per the instructions given on the
>> github page of npm.
>>
>> I can install npm packages normally, and i installed express by "npm
>> install express" command.
>> This is the app.js file am trying to run:
>>
>> var app = require('express').createServer();
>>
>> app.get('/', function(req, res){
>> res.send('hello world');
>> });
>>
>> app.listen(3000);
>>
>> This is the output:
>>
>> :~/app$ node app.js
>>
>> node.js:63
>> throw e;
>> ^
>> Error: Cannot find module 'express'
>> at loadModule (node.js:275:15)


Node looks for modules in $NODE_PATH or in node_modules directories from the current directory on up the directory tree.

When you did the ’npm install express’ were you in the directory “/home/node/app” directory? Do you see the express module under /home/node/app/node_modules?

—ravi



> at require (node.js:411:14)
> at Object.<anonymous> (/home/node/app/app.js:1:73)
> at Module._compile (node.js:462:23)
> at Module._loadScriptSync (node.js:469:10)
> at Module.loadSync (node.js:338:12)
> at Object.runMain (node.js:522:24)
> at Array.<anonymous> (node.js:756:12)
> at EventEmitter._tickCallback (node.js:55:22)
> at node.js:773:9
>
> VM is a Ubuntu 10.04.1 LTS 32 bit.
>
> --
> You received this message because you are subscribed to the Google Groups "Express" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
> To post to this group, send email to expre...@googlegroups.com.
> Visit this group at http://groups.google.com/group/express-js?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Brian Feister

unread,
Jun 13, 2013, 6:10:20 PM6/13/13
to expre...@googlegroups.com
Thanks David - that worked for me.



On Thursday, April 11, 2013 11:07:04 AM UTC-4, David Martinez wrote:
Guys,

I sorted out this problem just by updating npm this way: sudo npm update

Then after doing that I had no more that problem

Buvaneswari Chandran

unread,
Apr 8, 2014, 3:56:16 PM4/8/14
to expre...@googlegroups.com
Setting the NODE_PATH to the dir where the express module was installed worked for me.
Reply all
Reply to author
Forward
0 new messages