Giter VIP home page Giter VIP logo

Comments (17)

createdbyjurand avatar createdbyjurand commented on May 18, 2024 119

I think this is more of a previous npm version bug than nvm one.

However, to update npm delete in nvm/[node version] folder (for me it is v10.15.3) following files:

C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npm
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npm.cmd
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npx
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npx.cmd

Rename npm folder to npm2

C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2

Open any console with admin rights (or even right mouse click on vscode shortcut, than right mouse click on Visual Studio Code and hit Run as administrator) and type commands:

cd C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2\bin
node npm-cli.js i -g npm@latest

Done.

Delete C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2 folder.

from nvm-windows.

filipesilva avatar filipesilva commented on May 18, 2024 29

Heya, I just wanted to add that upgrading updating npm isn't quite as simple as just npm update npm:

$ npm update npm -g
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\kamik\AppData\Roaming\npm-cache\_logs\2017-08-24T07_56_26_609Z-debug.log

(I used -g here but I assume that's what you meant since you didn't say anything about going into the global directory. But if that is what you meant, I'm just describing the same thing in more detail.)

Here is a list of the things you need to do when not using NVM on the official npm wiki: https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows.

But there's actually an easier way if you're using NVM. Since NVM links both binaries and folders, you can just go and update the original global node modules manually. This doesn't require neither admin permissions nor moving files around.

First run node -v and take note of the version of node you're using (e.g v6.11.1). Then do this:

cd %appdata%\nvm\6.11.1
npm install npm@latest --no-save

The --no-save option is important to prevent npm from trying to find package.json in that directory, and from auto creating package-lock.json (in npm5 and up).

from nvm-windows.

KillyMXI avatar KillyMXI commented on May 18, 2024 22

Windows 10, PowerShell:

PS> nvm list
PS> cd "$env:APPDATA\nvm\v99.99.9"
PS> npm install npm --no-save

(Change digits to the node version where you want to update npm.)

from nvm-windows.

erikstagg avatar erikstagg commented on May 18, 2024 21

@createdbyjurand I updated your script so that you don't have to edit the script to run it, even when switching versions of node. I also took out @next because that installs a pre-release (non-stable).

$starting_path = Get-Location
$node_version = node -v
$node_path = "$env:appdata\nvm\$node_version"
Write-Host "node_version: $node_version"
Write-Host "Path used: $node_path"
cd $node_path
Remove-Item npm
Remove-Item npm.cmd
Remove-Item npx
Remove-Item npx.cmd
cd node_modules
Rename-Item npm -NewName npm-old
cd npm-old\bin
node npm-cli.js install -g npm
cd ../..
Remove-Item -Recurse -Force npm-old
cd $starting_path

from nvm-windows.

coreybutler avatar coreybutler commented on May 18, 2024 20

Just run npm update npm... same as without NVM for Windows.

from nvm-windows.

alexisCata avatar alexisCata commented on May 18, 2024 17

I think this is more of a previous npm version bug than nvm one.

However, to update npm delete in nvm/[node version] folder (for me it is v10.15.3) following files:

C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npm
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npm.cmd
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npx
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npx.cmd

Rename npm folder to npm2

C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2

Open any console with admin rights (or even right mouse click on vscode shortcut, than right mouse click on Visual Studio Code and hit Run as administrator) and type commands:

cd C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2\bin
node npm-cli.js i -g npm@latest

Done.

Delete C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2 folder.

The only solution that worked for me.

from nvm-windows.

8thHalfHour avatar 8thHalfHour commented on May 18, 2024 4

Thank you so very much to @createdbyjurand. This worked flawlessly! I wrote a script for it for PowerShell, if anyone wants it; you can run it form anywhere as long as you update the node version being updated (substitute both instances of Username and Version of Node with your own):

cd C:\Users\<Username>\AppData\Roaming\nvm\<Version of Node>
Remove-Item npm
Remove-Item npm.cmd
Remove-Item npx
Remove-Item npx.cmd
cd node_modules
Rename-Item npm -NewName npm-old
cd npm-old\bin
node npm-cli.js install -g npm@next
cd C:\Users\<Username>\AppData\Roaming\nvm\<Version of Node>\node_modules
Remove-Item -Recurse -Force npm-old

Run with the usual .\<filename>.ps1 from anywhere. 😎

from nvm-windows.

sediq-khan avatar sediq-khan commented on May 18, 2024 3

I am using Windows 10 and I spent a whole day on updating pm. Nothing worked but following.

https://www.wdiaz.org/update-npm-when-node-was-installed-using-chocolatey-on-windows/

Steps 1: Copy and Paste the following lines into a file somewhere in your directories and give it the .cmd extension.
Step 2: Double click the newly created "above" file.

You should be good to go now with the most up to date version of node.

from nvm-windows.

raikesy avatar raikesy commented on May 18, 2024 2

The solution outlined by @createdbyjurand does work but has to be repeated every time you install a new version of node. It also causes the following error message updating npm after the initial workaround:

js-algos-structures $ npm install -g npm@latest
C:\Users\jzrai\scoop\apps\nvm\current\nodejs\nodejs\npx -> C:\Users\jzrai\scoop\apps\nvm\current\nodejs\nodejs\node_modules\npm\bin\npx-cli.js
C:\Users\jzrai\scoop\apps\nvm\current\nodejs\nodejs\npm -> C:\Users\jzrai\scoop\apps\nvm\current\nodejs\nodejs\node_modules\npm\bin\npm-cli.js
+ [email protected]
updated 2 packages in 32.004s

C:\Users\jzrai\projects\js-algos-structures>npm-cli.js" install -g npm@latest
'npm-cli.js" install -g npm@latest' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\jzrai\projects\js-algos-structures>ENDLOCAL

C:\Users\jzrai\projects\js-algos-structures>EXIT /b 

I don't understand the inner workings enough to know if this is a bug with nvm, npm or scoop but, as it seems to be nvm, I think this issue should be reopened @coreybutler as updating npm is quite a fundamental operation which is currently completely broken with this set-up.
At the very least @createdbyjurand's workaround should be documented more visibly.
If this is definitely a bug with npm I will happily post an issue there.

from nvm-windows.

richteambs avatar richteambs commented on May 18, 2024 1

Thanks to @createdbyjurand !

I needed to update in C:\ProgramData\nvm\ rather than C:\Users\[user name]\AppData\Roaming\nvm in case that helps anyone else.

from nvm-windows.

musaab-abdalla avatar musaab-abdalla commented on May 18, 2024 1

I just updated with npm install -g npm@latest

  • cd to current node directory C:\Users\user_name\AppData\Roaming\nvm\v12.8.1
  • run npm install -g npm@latest
    Working great Thank you @filipesilva

from nvm-windows.

roa-nyx avatar roa-nyx commented on May 18, 2024 1

@coreybutler this might be more headache than it is worth, but as you say

It merely downloads the npm archive and extracts it to the appropriate installation folder. That's it.

Couldn't we then say that NVM's responsibility starts (and ends) at the installation of NPM? If so I feel like my concerns can be addressed by having something like nvm update-npm latest or something similar. This would in theory take the current version of node and install the specified version of npm to it. It could use a method similar to what's being outlined by @createdbyjurand or something simpler.

You mentioned that you also verified an issue exists in the official node release MSI install. Can you clarify what issue you verified? Was it with an older MSI installation that shipped with an older NPM? I'm running a clean system that hasn't had any node or npm installed prior to NVM and I'm running into these issues.

from nvm-windows.

raikesy avatar raikesy commented on May 18, 2024

I just spent hours trying to pinpoint the cause of this error before coming across this comment. Maybe this workaround should be displayed more clearly or this issue reopened as I'm sure trying to update npm with the standard command is quite a common operation and currently it fails and gives the very esoteric error message shown above.

from nvm-windows.

eroSilva avatar eroSilva commented on May 18, 2024

It worked for me, too. Thanks! :)

from nvm-windows.

Jafferwaffer avatar Jafferwaffer commented on May 18, 2024

Awesome help @createdbyjurand cheers

from nvm-windows.

8thHalfHour avatar 8thHalfHour commented on May 18, 2024

Thank you, @createdbyjurand ! I have been pulling my hair out trying to figure out why the regular commands were not working. This is fantastic! πŸ’―

from nvm-windows.

coreybutler avatar coreybutler commented on May 18, 2024

@raikesy - npm and nvm have no operational relationship... meaning nvm just leaves npm alone. It merely downloads the npm archive and extracts it to the appropriate installation folder. That's it.

NVM4W doesn't touch the executable files. Unlike nvm for *nix, there is no shim. When node.exe is executed, it's actually calling that file. There is literally nothing else running. npm calls node.exe internally whenever it executes a script, i.e. node npm-cli.js.

Tools like scoop, homebrew, chocolatey, etc may or may not modify behavior. I don't really know because I don't maintain those. However; I don't think any of those are the problem because I can replicate these problems with standard Node installs (i.e. no nvm4w, no package manager, just a straight up msi install from nodejs.org).

@createdbyjurand is correct that this behavior often comes from older versions of npm. npm has gone through a number of rather difficult design decisions, especially with versions shipping in the Node 8.x.x line where there were some hard-coded path files used for installation.

from nvm-windows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.