Node.js - cannot find module
Asked Answered
Z

3

15

I'm using Node Boilerplate and it all worked fine until I decided create another project on top of it (in another dir).

Now I have exactly the same code base (this project AS IS) in two different folders. I can run one of it without any problems but another one is failing with:

% node app.js
node.js:116
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Cannot find module 'connect/middleware/router'
    at Function._resolveFilename (module.js:299:11)
    at Function._load (module.js:245:25)
    at require (module.js:327:19)
    at Object.<anonymous> (/home/gotts/Sites/nodejs-uploadr/lib/express/lib/express/server.js:17:14)
    at Module._compile (module.js:383:26)
    at Object..js (module.js:389:10)
    at Module.load (module.js:315:31)
    at Function._load (module.js:276:12)
    at require (module.js:327:19)
    at Object.<anonymous> (/home/gotts/Sites/nodejs-uploadr/lib/express/lib/express/index.js:28:31)

There is a similar problem explained here - https://github.com/visionmedia/express/issues/535 which says that the problem is in the incompatible version of connect/express.

But how is this possible? The source code is exactly the same in two folders and it works fine in one copy and fails in another?

Zinkenite answered 13/3, 2011 at 17:20 Comment(0)
Z
7

OK, let me answer my own question:

Sorry for misinformation - those two folders were not exactly the same(I'm gonna need to learn unix diff better). And there it require("connect") in code

Local checkout of connect into /lib folder takes precedence but if it's not there - connect will be loaded from the ~/.node_modules as Ricardo previously set.

Zinkenite answered 14/3, 2011 at 12:35 Comment(0)
H
8

Do the two folders share a common parent? Node looks for modules in ~/.node_modules and /node_modules in your app dir.

Hengist answered 14/3, 2011 at 4:14 Comment(0)
Z
7

OK, let me answer my own question:

Sorry for misinformation - those two folders were not exactly the same(I'm gonna need to learn unix diff better). And there it require("connect") in code

Local checkout of connect into /lib folder takes precedence but if it's not there - connect will be loaded from the ~/.node_modules as Ricardo previously set.

Zinkenite answered 14/3, 2011 at 12:35 Comment(0)
I
5

@see node.js express module not loading properly in the last comment, maybe it helps

the basic idea behind it is to install the module inside your application folder, not on a system level

Ichang answered 21/5, 2011 at 12:52 Comment(1)
This works for me, but I'm confused as to why installing system level with -g doesn't find the module in the js file being run.Patrol

© 2022 - 2024 — McMap. All rights reserved.