How to Reinstall Broken npm - node.js

I just installed node v9.11.1 when I try to use npm I keep getting the following error:
npm WARN npm npm does not support Node.js v9.11.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
I tried to do npm i -g npm but it couldn't update itself, it just kept throwing the same error above.
When I run npm -v it says 5.5.1 it seems the latest version is currently 5.8.0.
I tried deleting the folder and running the repair function on the node.js installer, but it didn't replace the module.

Delete the Global NPM Folder
https://stackoverflow.com/a/5926706/349659
npm list -g
For Windows this will most likely be:
%AppData%\npm\node_modules
You can paste that into a folder's address bar and it will take you there.
Once there delete the folder named npm.
Download the Latest Release of NPM
https://github.com/npm/cli/releases/latest
Grab the zip and unzip it to your node_modules folder that you just deleted the npm folder from.
Rename the folder you extracted from the zip to npm
If you get any warnings about the file path or name being too long skip the warnings.
Update for Good Luck
Now you should be able to run npm i -g npm to update/reinstall npm without any warnings.
I find this step especially important if you had errors in Windows about the path or file name being too long.
You may get the following errors. If you do go and delete or move the files it has listed and you should be able to run npm i -g npm successfully.
npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Move it away, and try again.
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.

Somehow I had a broken installation of npm so reinstalling it with itself (e.g. npm install -g npm or similar) would not work.
The npm readme actually defines a very simple way to install npm again using this curl command:
curl -qL https://www.npmjs.com/install.sh | sudo sh
This installation script actually removes any existing npm installations, then installs the latest version for you.

Try this:
npm install npm#latest -g
More info here.

Try this command to reinstall npm
npm install -g npm-reinstall
If you are using a linux distribution add sudo
sudo npm install -g npm-reinstall

Since I am all about one-liners, let me make this very damn easy for you.
Open your GitBash or Cygwin(I think both GitBash and Cygwin stores the Windows pre-defined Environment Variables and paths in their storage, so this becomes way easy), on any path, and run this one-liner from there:
rm -rf $APPDATA/npm; npm install -g npm#latest; npm list -g;
rm -rf $APPDATA/npm; - this will purge the old global npm folder completely.
npm install -g npm#latest; - this will install the latest version of NPM available(so no need to install minor versions after this ;)).
npm list -g; - this will show you details of your NPM global profile.
If anyone insists on doing this in PowerShell then here's the way:
$env:Path += ";C:\Program Files\nodejs\"
cmd /c 'del /s /q /f %APPDATA%\npm && rd /s /q %APPDATA%\npm'; npm install -g npm#latest; npm list -g;
$env:Path += ";C:\Program Files\nodejs\" - Ensures that Nodejs is added to Path for atleast running PowerShell session. (Caution: Run this only once, as long as no errors.).
cmd /c 'del /s /q /f %APPDATA%\npm && rd /s /q %APPDATA%\npm'; - Ensures that the necessary step of fully purging the %APPDATA%\npm folder is done with measure.

For me even deleting npm folder or reinstalling Node didn't help. After updating Nodejs and npm to latest version (Node 10.19, npm 6.14.3) of my CentOS 6, I've got constant libs error with npm while Node was fine.
What's worked - n Node version manager. With this command I could reverse my npm version: n -p 6.13 link

Related

npm WARN: npm does not support Node.js v12.4.0

I've been getting the following warnings lately whenever I run any npm script:
npm WARN npm npm does not support Node.js v12.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/
It says that I should upgrade to a newer version, but v12.4 is the newest version. Even though the scripts run fine, I think there's no guarantee and something might break at any moment.
I've also tried updating npm in case there's a newer version using npm install npm -g but got the error:
npm ERR! path /usr/local/Cellar/node/12.4.0/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'] {
npm ERR! stack: 'Error: EACCES: permission denied, access ' +
npm ERR! "'/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
Then I've seen that Homebrew version of npm can't be updated using npm itself, so I tried updating through Homebrew using brew upgrade npm but got this error:
Error: npm 12.4.0 already installed
For some reason Brew mixes up nodes and npms versions.
What am I doing wrong and how can I get rid of this warning?
What worked for me:
if you try running this command "npm cache clean -f" and it doesn't work,
on your windows machine(mine is windows 10)
access the "npm" and "npm-cache" folders in this location "~\AppData\Roaming\"
delete these two folders "npm" and "npm-cache".
go to your windows search bar and search for Node, right click to open file location, run the uninstaller to uninstall NodeJs.
then visit nodejs.org and download and install node again, if you've already downloaded it, visit the folder where you downloaded it to reinstall it.
after installation, check your version of npm by typing "npm -v" on your command terminal to see the new updated version of npm installed on your machine.
now you're all set, Happy coding.
Seems like you messed up with permissions in /usr/local.
Here is how to fix that:
Fix /usr/local permissions:
sudo chown -R `id -un`:`id -gn` /usr/local
Clean npm cache and uninstall it:
npm cache clean -f
npm -g uninstall npm
Reinstall node (with npm)
brew reinstall node
Upgrade npm:
npm -g i npm
That should bring npm#6.9.2.
You should avoid using sudo while installing software with brew or npm, that could cause issues like this.
If you have nvm you may have an issue in which your node version installed at a certain version didn't match.
For example, I accidentally used: npm i -g node --force resulting in my nvm v12.21.0 to point to v16.5.0 (the latest version of node at that time directly downloadable).
To solve: I ran:
Just for good measure brew uninstall nvm
brew install nvm.
nvm uninstall 12.21
nvm install 12.21
Just for good measure I ran npm i -g npm resulting in the latest version of npm installed on that virtual node.
After installing within some repo (using npm i) you may also want to check your: ~/.npmrc.
email=myemail#company.com
registry=https://artifactory.company.com/npm/npm/
always-auth=true
user-agent=npm/6.14.11 node/v12.21.0 darwin x64
_authToken=siofjwoirgiowrgnioaenrvoianeoiio32noi23nio23nio23nio
It should look something like this: (or you might not have any of that.
Had the same issue with Debian 10 (buster) when I tried installing the npm and node.js. They were incompatible and wouldn't update. This was what I found works for me.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
The nodejs package was installed at a different path and I manually deleted the old package (in /usr/bin/) and added a symlink to point to the new one (in /usr/local/bin).
sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node
This is the initial printouts from running the commands. The npm version updates from 5.8.0 to 8.1.2. But the nodejs version stayed at 10.24.0 even after reboot with hash -r.
None of the answers here worked. I had to delete the npm and npm-cache folders, then reinstall npm. Details here: npm does not support Node.js v12.18.3
After step 4 posted by Styx, and if node claims installation fo a newer version but npm -v keeps showing outdated version
Code for Mac and node installed with brew:
cd /usr/local/bin/
mv npm npm-backup
mv npx npx-backup
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
npm -version
6.14.5
I hit this issue and the steps above didn't work for me. I think it can happen if you try to upgrade Node or NPM without updating the other also. At least I think that's what happened to me.
I was trying to create a new Angular project and I had a very old version on my machine. I got an error to upgrade Node, so I bumped it to the latest version. After that I got the error running any npm command.
I resolved it simply by going to:
https://nodejs.org/en/download/
Getting the latest version and installing that in a pkg file (mac). After install was complete I was able to run everything. I'm guessing it worked because the versions of each mismatched, so one wouldn't run without the other being downgraded.
I also tried the brew option but I was getting other issues. My corporate machine sometimes blocks installations in that route, so it might work for others.
For Windows, this was driving me crazy, and all of the above solutions were not working, I would still get the old version of node showing for node -v.
For me simply killing the terminal window and starting it again resolved the issue. No amount of cache clearing worked until this. I know it sounds dumb, but that's what resolved this for me in the end. Hope this helps someone else not lose hours farting around with this.
I've have this issue in npm -v package,so you have to easy step in follow of solve this problem.
npm use stable
nvm use stable
nvm cache clear
nvm install stable --default
you can closed the terminal then check the `npm --version
Looks like a permission issue. Try with sudo

Can't update npm packages: ERR! code EEXIST

I'm trying to to upgrade npm packages via
npm update -g
But, I get this error:
npm ERR! path C:\Program Files\nodejs\npm
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\npm: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm
npm ERR! Move it away, and try again.
I've googled but none of the solutions work. One sadi to remove the npm.cmd and npm files from here:
C:\Program Files\nodejs\
I tried that, but it fails as npm is now missing.
That folder, C:\Program Files\nodejs\, is actually a shortcut pointing to
C:\Users\lthurman\AppData\Roaming\nvm\v8.11.1
I'm using nvm to manage my node installations, any ideas on how to fix this?
Thanks
To resolve this issue I took the following steps
Where [userName] is your Windows user name -- [nodeVer] is your current version of Node, or the one that is giving you issues using NVM
Delete these four files:
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npm
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npm.cmd
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npx
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npx.cmd
Then in C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\node_modules\, rename the npm directory to npm_old
Open up your console of choice -- run as admin if necessary -- and navigate into the \npm_old\bin directory then install NPM at latest (or replace latest w/a version of your choosing) using the command below:
node npm-cli.js i -g npm#latest
Clean-up by deleting the npm_old directory from earlier. Now all should be good to go...I hope!
Try doing this below command after deleting the folder C:\Users\xxx\AppData\Roaming\npm, C:\Users\xxx\AppData\Roaming\npm-cache.
npm install -g npm#latest
It will fixed it by forcing the install with --force
npm install -g npm#latest --force
Uninstall old version first
npm uninstall -g your-package-name
install the latest
npm install -g your-package-name#latest

Updating npm when using nvm-windows

I'm using nvm-windows version 1.1.7.
I just installed node 11.9.0.
nvm installs npm version 6.5.0 together with this node version.
However, there's npm version 6.7.0 available already.
When I now do npm i -g npm I get:
npm ERR! path C:\Program Files\nodejs\npm.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.
I found no way to avoid this.
This is a duplicate from my answer here: https://stackoverflow.com/a/50955293/491553
Here is how I upgrade npm when running nvm-windows:
cd %APPDATA%\nvm\v14.20.0 # or whatever node version you're using
move npm npm-old
move npm.cmd npm-old.cmd
move npx npx-old
move npx.cmd npx-old.cmd
cd node_modules\
move npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm#latest --force
And boom, upgraded.
Several workarounds are available in this Issue on the nvm-windows github repo:
https://github.com/coreybutler/nvm-windows/issues/300
There are examples using DOS, PowerShell, bash, and batch scripts.
I have windows 10 operating system.
I installed in following way.
cd %APPDATA%\nvm\v8.11.3
move npm 5.6.0
move npm.cmd 5.6.0.cmd
cd node_modules\
move npm 5.6.0
cd 5.6.0\bin
node npm-cli.js i -g npm#latest
I had to force it :-/
When it came to
node npm-cli.js i -g npm#latest
I'd rather had to use
node npm-cli.js i -g npm#latest --force
probably to overcome a permission error involved in overwriting the "C:\Program Files\nodejs" link.
download this updateNpm.bat file
open powershell in that same folder and run this command updateNpm.bat latest
I tried the script and other solutions, this by far is the easiest way:
Navigate to the relevant Node folder (cd C:\Users\yourUser\AppData\Roaming\nvm\vxx.xx.x)
rename npm -> npm2
rename npm.cmd -> npm2.cmd
rename npx -> npx2
rename npx.cmd -> npx2.cmd
Run npm2 install -g npm#your-version
the new npm will create npm, npm.cmd, npx, npx.cmd files, so you can remove the previous renamed files
I also found it necessary to install windows-nvm to c:\nvm and c:\nodejs to prevent issues with unsupported paths with spaces.
rm C:\nodejs\npm*
rm C:\nodejs\npx*
mv C:\nodejs\node_modules\npm C:\nodejs\node_modules\npm-old
node C:\nodejs\node_modules\npm-old\bin\npm-cli.js i -g npm#next
For me I only get the problem when updating npm with npm v6.
So using a newer version of npm via npx to run the upgrade works for me.
For the very newest version
npx npm install -g npm
Or use a specific version
npx npm#7 install -g npm#7
I faced this problem today, the way i solved it was installing latest node with nvm then copying the npm files from latest to the version i am on.
nvm install latest
cd AppData/Roaming/nvm/LATEST
xcopy npm.cmd ../LTS && xcopy npm ../LTS && xcopy node_modules/npm ../LTS
I then confirmed it working by trying to compile my code that breaks on latest.
This worked for me:
curl -L https://npmjs.org/install.sh | sh
If you already have git bash installed, use it there.

Why does the newest Angular CLI have a corrupted packages?

I installed the latest Node and Angular on Windows 10
npm install npm#latest -g
npm install -g #angular/cli#latest
But when I try to start a project ng new new-project I get the following error
npm WARN tarball tarball data for #angular/compiler#^6.1.0 (sha512-TY6axB1c7VvYXf+ebFDq3Ej+edgii3CDxew8HnyTFAWeDF2Gh8io1vTYwtdyDka6U53ASaheM1HpiUjzvYH0jQ==) seems to be corrupted. Trying one more time.
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\admin\Desktop\...\node_modules\.staging\#angular\common-6be83a81\locales\si.js'
...
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\admin\AppData\Roaming\npm-cache\_logs\2018-10-08T01_01_48_404Z-debug.log
Package install failed, see above.
I tried to uninstall Node.js and Angular CLI completely and then reinstall again
npm install npm#latest -g
npm install -g #angular/cli#latest
But still the same error ..... So I googled this issue. It seems like some people had it too, but then it magically disappeared for some people.
How to fix this?
I was getting the same below error when attempting to a create new project using ng new command.
npm WARN tarball tarball data for #angular/compiler#~7.2.0
(sha512-5yb4NcLk8GuXkYf7Dcor4XkGueYp4dgihzDmMjYDUrV0NPhubKlr+SwGtLOtzgRBWJ1I2bO0S3zwa0q0OgIPOw==)
seems to be corrupted. Trying one more time.
I tried many things but what did not worked and what finally worked for me I have listed below. My working node version is 12.2.0 and npm version is 6.9.0 (i.e. latest version).
What did not worked:
Downgraded node js to other lower versions (tried many version)
Deleted package-lock.json file from project and executed npm install
Executed npm install --registry https://registry.cnpmjs.org instead of npm install
Deleted npm and npm-cache folders from AppData\Roaming and then again installed node js
Deleted node_modules folder, executed npm update and then executed npm install
Executed npm cache clean --force and then executed npm install
Reinstalled #angular/cli
Checked for any firewall / antivirus (in my case it was disabled)
Opened node command prompt as an administrator
Checked user permissions for the project folder
Finally what worked is:
Installed the component for which it was giving error. npm install -global #angular/compiler
I had the same problem with node 12.13.0 and npm 6.13.0
npm WARN tarball tarball data for #angular/compiler#^7.2.11 (sha512-5yb4NcLk8GuXkYf7Dcor4XkGueYp4dgihzDmMjYDUrV0NPhubKlr+SwGtLOtzgRBWJ1I2bO0S3zwa0q0OgIPOw==) seems to be corrupted. Trying one more time.
For me the problem was npm. After upgrading npm to the newest version with npm i -g npm#latest the problem vanished. So it seems to be a problem with npm itself and not the Angular/CLI.
upgrade your NPM version use this command i -g npm#latest it works like magic

How can install a new version of NPM ( 1.1.24 )?

I want to install the latest stable version of node - Version 0.6.19 (stable).
http://blog.nodejs.org/ indicates to upgrade to NPM to 1.1.24
Is there a simple way to upgrade to this? I can't figure out how exactly to download and target this version.
The below gives me npm -v 1.0.106
npm upgrade npm
or
npm upgrade npm 1.1.24
Update 2 (03/11/15)
Courtesy: whyleee
On Windows npm is installed together with node in "Program Files". Use npm install npm -g to install it in "%AppData%\npm" and delete 'npm', 'npm.cmd' files from "C:\Program Files\nodejs" dir (because your PATH is looking there first). After that you can use npm update npm -g in the future
According to the docs
For windows (it also worked on Mac for me)
To update npm, run the npm update npm -g command.
Also verify this
Hope this helps
The only thing that worked for me was (from npm readme)
Fancy Windows Install
You can download a zip file from https://npmjs.org/dist/, and unpack
it in the same folder where node.exe lives.
In my case folder is :
C:\Program Files (x86)\nodejs
Edit: It seams that newer versions of npm does not exist on address I wrote. I will copy paste instructions from npm git page
You can download a zip file from https://npmjs.org/dist/, and unpack
it in the same folder where node.exe lives.
The latest version in a zip file is 1.4.12. To upgrade to npm 2,
follow the Windows upgrade instructions in the npm Troubleshooting
Guide:
https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows
If that's not fancy enough for you, then you can fetch the code with
git, and mess with it directly.
In ubuntu you can upgrade it using
sudo npm update npm -g
In windows, to install latest version of npm
npm install npm#latest -g
&
In ubuntu you can use
sudo npm install npm#latest -g
*note: the latest version till sept 12 2016 is
(The current stable version of npm is) 3.10.7
check version by running on command prompt
npm -v
https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows
Option 3: navigate to C:\Program Files (x86)\nodejs with cmd.exe and then run the installation without -g:
This sovled it for me.

Resources