I want to install packages locally, but npm is always installing packages to the global location. I'm running the following command:
npm install serialport
I do not have a .npmrc command and I'm not using the -g flag, so I don't know why it's not installing locally. Here's a snippet from the config dump showing that global is false: $ npm config ls -l | grep global global = false globalconfig = "/usr/local/etc/npmrc" globalignorefile = "/usr/local/etc/npmignore"
And the packages are still being installed like this
[email protected] ../../../../node_modules/serialport
So unless I am totally wrong about what "local" means, this seems wrong. I was under the impression that "local" meant in the current working directory so that I could do a "require" in my main code file. See: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/ as referenced in a previous npm related question.
Can someone please give me some hints on this? Thank you very much.
P.S. It's not specific to the serialport module. It's happening with all of them.
The error in NPM, 'error package install failed, see above', can occur when the user creates a new project in Angular using Node. js using VS code. This means that NPM is corrupted in your system, and must reinstall NPM.
You can install a package locally if you want to depend on the package from your own module, using something like Node. js require . This is npm install 's default behavior.
The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk. The -g or --global argument will cause npm to install the package globally rather than locally.
Most of my answer can be found: http://npmjs.org/doc/folders.html#More-Information
What I understand is that npm will try to install it in a sensible location. So if you have a project/node_modules
directory and you are in /project and do npm install it will use product/node_modules
.
Now if you accidentally did a cd project/css
and do npm install then npm will traverse up until it finds your node_modules
directory. This is to prevent you from accidentally installing it in your project/css
.
So in your case you have a node_module directory somewhere in the path of your project. So my guess is that you can fix it by either deleting that directory or manually creating a node_modules
dir in your project folder.
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