So I realize that this is a fairly generic title and question, but I've scoured through so many answers, but sadly none of them seem to be working for me. I'm hoping with a little more information from myself perhaps someone has a specific answer, or knows exactly which answer to redirect me to.
My problem: when I install node modules globally (e.g. npm install -g nightmare
) I'm unable to access them in my project folder. I get the error:
module.js:471
throw err;
^
Error: Cannot find module 'nightmare'
...
From what I've read so far installing the module locally inside the project folder seems to be the preferred practice (is this true?), but for now during the development phase I'd like to be able to use the modules I have installed globally. I'm newer to node.js so I'm still discovering what the "usual practice" is for these things though. I first installed Node using Homebrew, but being as I had issues with how things were installing and the pathing (which people were saying is common when using Homebrew), I decided to try a clean slate, uninstalling Homebrew, then eventually Node and NPM as well. I reinstalled just Node and NPM via the site, but am still having no luck being able to access my global modules.
I'm pretty confused at this point because I have some node_module files and packages in some random spots, but not where my current global packages are being installed. I'm assuming leftover from a previous installation. That being said I've adjusted my $NODE_PATH
several times in hopes that I could access the modules, but no such luck with that.
The current installation spot according to a --verbose
install is /Users/<user>/.npm-packages/lib
, which I thought was strange being as a lot of the people already answering this question are correcting their paths to things like /usr/local/lib/node_modules
which has things in it for me, but not the modules installed. I'm assuming that (because of the 'local' file it's in) this is the local installing... maybe? To be honest I'm pretty confused at this point as far as why everything is installed where it is and why, even with changing the $NODE_PATH
I'm unable to access the modules.
If I've missed something or need to include some other output please feel free to ask and prompt for more. I'm not sure what else is needed for more direction.
Thank you in advance!
You have 2 options, either installing locally:
npm install nightmare --save
Or creating a local link to the global package:
npm install -g nightmare
npm link nightmare
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