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?
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.
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.
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.
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With