Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - cannot find module

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 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? Source code is exactly the same in two folders and it work fine in one copy and fails in another?

like image 653
user80805 Avatar asked Mar 13 '11 17:03

user80805


People also ask

Can not find module in node JS?

If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.

Can not find module node path?

To solve the "Cannot find module path or its corresponding type declarations" error, install the types for node by running the command npm i -D @types/node . You can then import path with the following line of code import * as path from 'path' .

How do I fix module not found?

To solve the "Module not found: Can't resolve" error in React, make sure to install the package from the error message if it's a third-party package, e.g. npm i somePackage . If you got the error when importing local files, correct your import path.

How do I know if a node JS module is installed?

To list the modules installed locally in a project, enter the project directory and execute the npm list command, as shown in the example below.


1 Answers

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

like image 163
Ricardo Tomasi Avatar answered Sep 19 '22 10:09

Ricardo Tomasi