Can't update npm packages: ERR! code EEXIST - node.js

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

Related

Angular8 node js and npm installation problems

I'm learning angular js. For this I've install nodejs and git. And I've run following command on CMD:
npm install -g #angular/cli#latest
After some time following error occurred
npm WARN rollback Rolling back #schematics/angular#8.3.21 failed (this is
probably harmless): EPERM: operation not permitted, lstat 'C:\Users\User
Name\AppData\Roaming\npm\node_modules\#angular\cli\node_modules\#schematics'
npm ERR! code EEXIST
npm ERR! path C:\Users\User
Name\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng
npm ERR! dest C:\Users\User Name\AppData\Roaming\npm\ng.ps1
npm ERR! EEXIST: file already exists, cmd shim 'C:\Users\Chaitanya
Kulkarni\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng' ->
'C:\Users\Chaitanya Kulkarni\AppData\Roaming\npm\ng.ps1'
npm ERR! File exists: C:\Users\User Name\AppData\Roaming\npm\ng.ps1
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User Name\AppData\Roaming\npm-cache\_logs\2020-01-
04T12_12_30_922Z-debug.log
Can you please explain what is that error and how I could solve this. I am using Window 10.
Perform following steps:
Completely uninstall angular-cli from your machine
npm uninstall -g angular-cli
Clean npm cache
npm cache clean --force
Reinstall angular cli,
npm i #angular/cli#latest -g
Run this commands and manually delete the exist files if does not work.
Completely uninstall angular-cli from your machine
npm uninstall -g angular-cli
Clean npm cache
npm cache clean --force
Reinstall angular cli,
npm i #angular/cli#latest -g
Delete this file going to the location.
C:\Users\Chaitanya Kulkarni\AppData\Roaming\npm\ng.ps1
You can try opening the Command Prompt with Administrator privileges and then run the command.
Try to run following command in terminal
npm install -g #angular/cli#latest --force
In the terminal navigate to the following path:
C:\Users\UserName\AppData\Roaming\npm\node_modules
and delete angular file and reinstall cli.
That worked for me.
Also do check if you've set your path variables correctly.

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.

Cannot find module #angular\cli\bin\ng

I'm getting into trouble with anngular-cli installation because it doesn't recognize the ng command in my git bash but it works in my cmd on Windows 7.
I looked for some issues on the web but I didn't really find a solution.
Here, the error :
ng -v
module.js:549
throw err;
^
Error: Cannot find module 'C:\Program
Files\Git\node_modules\#angular\cli\bin\ng'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
This error happened the first time I used ng after installing Node and angular-cli globally.
I didn't get this error when I was working on my laptop on Windows 10.
Problem:
Error: Cannot find module
'..\AppData\Roaming\npm\node_modules\angular-cli\bin\ng' angularJs
Solution:
uninstall angular cli if you have already installed it
npm uninstall -g #angular/cli
Delete the C:\Users\Satish\AppData\Roaming\npm\node_modules#angular folder if it still exists after the uninstall
reinstall angular-cli globally
npm install -g #angular/cli
First, uninstall the angular cli using
npm uninstall -g #angular/cli
Then delete the "NPM" and "Npm-cache" folder under "Roaming" folder.
Now again install the Angular cli using
npm install -g #angular/cli
It worked for me only by removing npm and npm-cache folders from AppData then running :
npm uninstall -g #angular/cli
Then running :
npm install -g #angular/cli
In my case, i fixed it simply just by renaming my project folder.
before : "d/Gdrive/Sem 6 & 7/[project name]"
after : "d/Gdrive/Sem 67/[project name]"
So i guess u may not put special characters in your folder name.
Looks like a dependency was removed somewhere. I worked around this by:
For local angular-cli: npm install #angular-devkit/core --save-dev
For global angular-cli: npm install -g #angular-devkit/core
Edit: As discussed below, you should perhaps not use --save-dev here.
Remove existing angular
npm uninstall -g #angular/cli
and Install
npm install -g #angular/cli --force
reinstall node_modules
git clean -dfx
npm i
if persist, use yarn install first, then repeat above
The git bash is installed in C:\Program Files\Git where you never find the node_module folder that's why this error occurred
When you hit ng command from CMD it will look node_module folder in C:\Users\uername\AppData\Roaming\npm\ - where npm install global dependency and eventually it finds node_modules folder.
Basically for windows try to run from cmd.
In my case the problem is
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\node_modules\#angular\cli\bin\ng.js
npm ERR! dest C:\Program Files\nodejs\ng
npm ERR! EEXIST: file already exists, cmd shim 'C:\Program Files\nodejs\node_modules\#angular\cli\bin\ng.js' -> 'C:\Program Files\nodejs\ng'
npm ERR! File exists: C:\Program Files\nodejs\ng
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<UserId>\AppData\Roaming\npm-cache\_logs\2022-01-03T20_13_43_709Z-debug.log
Solution:
I use this comment of npm 5 line on the shell
$ npm ERR! File exists: C:\Program Files\nodejs\ng
Delete the file ng and run:
npm install -g #angular/cli
And Done!
I faced the same problem but running npm install solved my problem.
I had this error in Angular Console starting with release 11.
I was missing a locale cli. So
npm install #angular/cli
solved my problem
It might be an issue with the package installation. Sometimes the installation might brake due to network issues. Also the access permission affects the installation.
So, try to install the package by running command prompt (CMD) as Run as administrator.
Follow the steps to resolve the issue.
1.Run CMD as Run as administrator mode.
2.Uninstall angular cli.
npm uninstall -g #angular/cli
3.Remove npm package files from the appdata folder.
Open Run option by pressing Windows + R key. Then type %appdata% and press OK.
Open the npm folder from the Roaming folder that you got in the explorer.
Delete ng and ng.cmd files from the npm folder if exists.
Open node_modules folder from there and delete #angular and angular/cli folder if exists.
4.Reinstall the angular cli
npm install -g #angular/cli
npm install --legacy-peer-deps
npm cache clean --force
If the environment variable path is properly set , please run ng in an angular project otherwise it will keep showing that error
once you run npm uninstall -g #angular/cli, check if there is an error in the console, it is usually a message with red line says "err!", mine said that it was unable to delete a file , follow the path of the file and delete manually ,then run npm uninstall -g #angular/cli and npm uninstall #angular/cli, when it goes successfully , run npm install -g #angular/cli , that should fix it.
If most suggested and obvious solution below do not work
npm uninstall -g #angular/cli
remove roaming -> npm
npm install -g #angular/cli
Try to upgrade Node.js version. This solved the problem in my case after severl hours of investigation
Try deleting the node_modules folder (not the AppData one), the one in your project folder, and try reinstalling angular again.
If you have MAC(Mackbook) pc use brew command because we can not install angular-cli from npm command
brew install angular-cli

How to Reinstall Broken npm

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

I can't install npm packages in my Ionic project folder and get error hints: No repository field. No license field. How to fix it?

Whatever npm package I try to install, I got such error hints:
"D:\Program Files\nodejs\node.exe" "D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" install ionic
Standard error:
npm WARN my-project-name#1.1.1 No repository field.
npm WARN my-project-name#1.1.1 No license field.
npm ERR! Cannot read property '0' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\my-user-name\AppData\Roaming\npm-cache\_logs\2017-08-28T03_14_36_746Z-debug.log
Process finished with exit code 1
I'm not familiar with npm and node.js, and I don't understand what the error hints mean.
The error log that it mentioned is a huge file with thousands of lines, which is even harder for me to understand. But basically I found the same error hints as the above at the bottom part of the log file.
I can install packages in the node.js folder with npm directive normally. But I just can't install them in my project (Ionic v1) folder, always getting the above three hints: No repository field. & No license field. & Cannot read property '0' of undefined.
I installed the latest version of Ionic (3.9.2) in the node.js folder. But because my project was developed with Ionic v1, so I installed version 1.3.3 of Ionic in my project folder. Is it relevant to the error hints that I got?
And I can't downgrade npm successfully by running npm install -g npm#4.2.0 command, getting such error hints:
D:\Program Files\nodejs\node_modules>npm install -g npm#4.2.0
npm ERR! path D:\Program Files\nodejs\npm.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete D:\Program Files\nodejs\npm.cmd: is outside D:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: D:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.
Try downgrading NPM
with npm install -g npm#4.2.0
Can you give bit more details: NPM version, on which folder you are running the install command and is your project connected with Git?
You can also try npm init in project directory to initialize repository and license etc if you want to [they are optional]
To downgrade NPM in windows, you need to start the command prompt with Administrator privileges.
Right click on command prompt shortcut and choose Run as Administrator.
You can also set the properties of the shortcut to always Run as Administrator:
Right click -> properties -> Shortcut tab -> Advanced -> click Run as administrator checkbox
Installing NPM as a different version now works
npm install -g npm#4
Note: If your NPM folder/install is missing, you will have re-install node.js to re-install NPM .

Resources