npm not defaulting local installs to ./node_modules - npm

When I try to do a local install (eg. npm install socket.io), it's putting the module in the ~/src/node_modules/ folder. npm root reports this folder as well. I must have screwed up npm's settings during some bleary eyed late night session, but I can't figure out how to get it set back to ./node_modules as the default. Anyone know what I screwed up, and how to set it back to the default?
Update
I have tried npm config set root ./node_modules but npm root still reports ~/src/node_modules as the root. I also checked .bash_profile and no node related settings are being made in it.

A quick npm uninstall npm -g and then another install from the npm website should get your defaults back.
Normally reinstalling is a pain but with your package.json files you can get everything set back up with a quick npm link

Related

NPM insists on using the wrong registry URL

Using NPM to install dependencies, including one that is stored in Verdaccio running locally.
Somehow NPM is stuck attempting to load the Verdaccio dependency from localhost even though the command to install from the corrected location has been run npm install --save --registry http://CORRECT-URL ...
Using rm -rf node_modules package-lock.json and removing the dependency from package.json, then running the install again - still DOES NOT WORK. Every time the install command completes, package-lock.json STILL uses localhost to resolve the registry.
Removing localhost from ~/.npmrc and running npm set registry http://CORRECT-URL also didn't help.
Please help. Where is NPM remembering localhost and insisting on using it???
UPDATE - Using npm install -ddd
Attempted to use npm install -ddd to see where npm is picking up the package. The output shows the CORRECT-URL, but when it is done, package-lock.json still lists localhost.
Note all of the following:
Removed all references to the PACKAGE from package.json and package-lock.json
Verified no references to localhost in either file
Removed node_modules/PACKAGE_DIR with rm -rf
Removed PACKAGE from node_modules/.package-lock.json
Searched for .npmrc and npmrc in the build tree and found two empty files:
node/node_modules/npm/docs/public/configuring-npm/npmrc
node/node_modules/npm/.npmrc
~/.npmrc has 2 entries for the CORRECT_URL in the following forms:
//:/:_authToken="<AUTH_TOKEN>"
registry=http://:/
Stumbled upon this post while trying to debug the exact same situation. What ended up solving this for me was to blow out package-lock, run npm rebuild, then npm install --registry . Hope this helps someone in the future!

npm doesn't uninstall packages

I've been trying to remove some packages that I installed with npm but it doesn't remove them. After running npm uninstall -g package the package is still executable in my terminal and it is still in the path where npm binaries are being installed.
Also, why is npm installing packages in ~/.local/share/npm/bin/ ? It's the first time that I've seem npm installing packages there. I had a problem a few weeks ago when installing some language servers but they weren't executable, turns out I had to add ~/.local/share/npm/bin to my $PATH because that's where npm was installing everything. And now npm doesn't remove any package installed there. I've already look into the npm config (npmrc) but I don't see any option changing the install path. The only environment variable related to npm that I have is to set the user config in ~/.config/npm instead of ~/.npmrc.
I have others machines with the exact same settings and npm it's not installing packages in ~/.local/share/npm/bin/ and I'm able to uninstall packages normally.
Does anyone knows whats wrong with npm ?
npm --version 7.8.0
my config:
cache=/home/user/.cache/npm
init-module=/home/user/.config/npm/config/npm-init.js
package-lock=false
tmp=/run/user/1000/npm
Okay I noticed that if I reinstalled the packages that I couldn't remove they went into a different folder /user/bin/ with the node_modules being in /user/lib/node_modules. Before it was in ~/.local/share/npm/lib. Now with the packages were they belong I can't remove them without issues. No idea why those packages were originally installed in a different path.

A bunch of errors when running npm install

When I run npm install on my xampp laravel setup I get a bunch of errors. log is LONG and shown below. I don't even know where to start
I've tried deleting my node_module folder (that was a random guess, nothing changed)
I've tried to run npm install -g (didn't work either)
I'm installing the root of my project and I've got a composer.json file.
Error log:
Errorlog link
Try just deleting the node-sass folder in node_modules (if it's there), then run npm install node-sass#4.9.2 --save, and run npm install again!

How can I remove the npm registry from my machine?

I published a module to npm. When I uninstall it and try to reinstall it, this is always done from a cache ( it is done even if I'm not connected to the internet, I just get a warning ). I would like to try if my module installs correctly from the remote npm repository on a fresh npm registry.
I tried to remove Node.js and reinstall it, but it does not help. There is no "npm" in the list of my applications that I could remove, only Node.js is listed. This is on a Windows 10 machine.
Where is the npm registry located and how can I remove it entirely?
You have to clean your NPM cache and then clear your registry using the below commands.
npm cache clean
npm config delete registry
Thanks
npm config delete registry
This worked for me

Does npm delete downloaded module if the installation fails?

When I try to install something with npm it fails quite often (much more often that apt-get for example), and it will display "see log file for details" or "make in the directory failed". But when I try to inspect the directory said it will not be found. Does NPM simply delete every thing it just downloaded if anything fails during installation? Why would it tell me to check the directory then if it deleted it?
npm keeps downloaded packages as tarballs inside a cache folder.
see: https://www.npmjs.org/doc/cli/npm-cache.html
When you run npm install and something goes wrong, it will try to undo and remove the packages from your current location, but it should leave the cached tarballs alone. Sometimes the cache can have a bad package-tarball.
You can force npm to install without using the cache like this npm install --force. Or, if you really must, you can clear out the whole cache like this npm cache clean.
Remember: npm installs packages into the current folder, or wherever your package.json can be found