Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node v0.8.5 REPL: Cannot find module when requiring npm installed module

Tags:

node.js

npm

I have a node app with a package.json file declaring my dependencies.

I've run npm install to install those deps to a local node_modules folder, and when I run my app, everything works great.

The problem is when I try to spike out some new functionality by firing up the node REPL:

$ node           
> require('hubot');
Error: Cannot find module 'hubot'

In the REPL, it doesn't seem to know to look inside node_modules. Is this expected behavior, or is hubot weird?

like image 839
adamesque Avatar asked Aug 07 '12 17:08

adamesque


People also ask

How fix npm module not found?

If you have run the npm install command before, then it's possible that the installation of the module is incomplete or corrupted. Delete the node_modules/ folder using the rm -rf node_modules command, then run npm install again. That may fix the issue.

How do I resolve Cannot find module error using node JS?

To solve the "Cannot find module" error in Node. js, make sure to install the package from the error message if it's a third party package, e.g. npm i somePackage . If you get the error with a local module, make sure to point the node command to a file that exists.

How do I reinstall npm?

Using the official Node installer is the easiest way to reinstall Node. js and npm on your Windows environment. To use this option, you can go to the Node. js download page and reinstall the latest Node.


1 Answers

You can set the env variable NODE_DEBUG to see the paths that are tried by node:

export NODE_DEBUG=module
> require('toto')
Module._load REQUEST  toto parent: repl
looking for "toto" in ["/Users/laurent/repl/node_modules","/Users/laurent/node_modules","/Users/node_modules","/node_modules","/lusr/local/bin/node","/Users/laurent/.node_modules","/Users/laurent/.node_libraries","/usr/local/lib/node"]
like image 67
Laurent Perrin Avatar answered Oct 03 '22 07:10

Laurent Perrin