coreybutler / nvm-windows

A node.js version management utility for Windows. Ironically written in Go.
MIT License
37.09k stars 3.3k forks source link

nvm installs node but fails to deliver npm #456

Closed dcoferraz closed 4 years ago

dcoferraz commented 5 years ago

My Environment

I'm using NVM4W version:

I have already...

My issue is related to (check only those which apply):

Expected Behavior

After running nvm install latest that node version 12.5.0 and npm version v6.9.0 is installed.

Actual Behavior

After the install command, no errors are shown:

2019-07-03_09h10_55

the following issue occurs:

2019-07-03_09h11_08

The node_modules/ folder is empty:

2019-07-03_09h32_34

Steps to reproduce the problem:

Just install a version and check what happens. don't know exactly how this works but it seems to be something related to the new npm/cli project url change.

coreybutler commented 5 years ago

Are you 100% certain you're running 1.1.7? I ask because the npm/cli change was a hardcoded URL issue that existed in 1.1.6 and was fixed in 1.1.7.

dcoferraz commented 5 years ago

unfortunetly, 100% certain @coreybutler hahaha

here's my screenshot of the version:

2019-07-03_13h33_44

A friend of mine just installed nvm 1.1.7 on his machine and I upgraded mine as well to get the latest version of npm, with no luck unfortunetly

coreybutler commented 5 years ago

Sorry, had to ask :-)

I cannot recreate this.

image

Typically it comes down to a) permissions, b) network issue during the download. Sometimes the network issue is on the remote server, especially when a brand new node/npm release has been pushed. This error message crops up all the time, but for lots of different reasons, making it difficult to identify the real source of the issue.

gsicoli commented 5 years ago

To reproduce this issue I had to uninstall Node and NPM and do a fresh install using only NVM, then I get the error.

pwrshell-nvm-install-latest

I've noticed that during the install process the NPM related stuff is downloaded to a temp folder, but later it's never moved anywhere and the temp folder is deleted. Even running powershell as Administrator, so I don't think it's permission related.

During install: during-install

After install: after-install

coreybutler commented 5 years ago

@gsicoli You're correct that npm downloads to a temp directory and is then moved. If the move operation is silently failing, it would cause the directory to be deleted without moving npm where it needs to be (i.e. this behavior).

Are you prompted when you run nvm use or nvm install? Running as an administrator doesn't necessarily mean the account has elevated permissions. Typically, Windows will prompt you to elevate permissions. For an admin account, it's automatically granted, but it still requires the user to say "OK".

gsicoli commented 5 years ago

It prompts when I don't run as administrator. If I run as administrator it doesn't prompt... Nonetheless the effect is the same.

mvarendorff commented 5 years ago

Facing the same issue on Windows 10. If there is any information I can provide, I will be happy to help!

It does not seem to be related to a certain version of node though; the node_modules folder is always empty for the versions I attempt to install. I am prompted for elevated permissions.

Didovgopoly commented 5 years ago

Have the same problem. Is there a workaround?

liuwenzhuang commented 5 years ago

Have the same problem. This is my attempt and works for me:

  1. download the need node version from https://nodejs.org/en/download/releases/ in zip format(or other format)
  2. Delete node_modules directory if it already exist in version drectory that located in nvm install directory(eg. C:\Users\USER_NAME\AppData\Roaming\nvm\v8.11.4).
  3. unzip the file from step 1, and copy node_modules directory to version directory infered in previous step.
  4. npm works
Niels-75 commented 5 years ago

Have the same problem. So, I have applied workaround from @liuwenzhuang. Indeed, now npm works fine. However, I get following error on npm up -g 62166164-56513a00-b320-11e9-8728-4d0cfeb758a9

PostImpatica commented 5 years ago

Turning off McAfee and running install from admin console fixed this for me.

Niels-75 commented 5 years ago

@helzgate: This makes no sense for me. My virus logs show exactly nothing. Can you provide a log of your McAfee activity?

maru-sama commented 5 years ago

I can confirm this. With mcafee enabled npm is unpacked but the move fails without any error. McAfee logs show nothing at all. Disabling mcafee during installation fixes the issue. @coreybutler I know it is not a nice solution, but apparently the unzipping works so is would it be possible to directly unpack in the nodes_module/npm folder instead of unzipping to temp and moving?

matthew-dean commented 5 years ago

I'm running into the same issue, but it seems to happen only with installing node 6 (or happens because I installed node 6 after doing nvm install latest?). NPM installation hangs indefinitely, and I run into the same npm-cli error as listed above.

matthew-dean commented 5 years ago

I have McAfee Endpoint Security installed, but as it's a managed PC in an office, there's no way to disable it to see if that's the issue. NPM continues to hang after 10 mins of going into the installation process. Is there not a way to modify NVM to at least detect hangs or that a process is not completed as intended?

matthew-dean commented 5 years ago

Note, this comment totally works! Would be great if this is what the nvm installer did.

mvarendorff commented 5 years ago

@matthew-dean Same here with McAfee. Though they didn't properly define my permissions so I can disable it. I will see if that is the cause of the issue tomorrow when I am back at work. I wouldn't be surprised; the package installer of dart reported a similar issue when installing some package (which also worked through downloading to temp and then moving somewhere else).

mvarendorff commented 5 years ago

Yup this is indeed the issue for me! There is some operation there that McAfee Endpoint Security silently prevents.

Installing any version with McAfee active => no npm Installing any version with McAfee disabled => npm is included and working fine

Niels-75 commented 5 years ago

Is the error mentioned above, when executing npm update -g, related to McAfee as well? Or is this a side effect of the workaround?

mvarendorff commented 5 years ago

Don't think so. It didn't change anything for me if I disabled McAfee or not. Also note that there are already two issues on that topic (a longer one and a shorter one with a script that allows you to still update npm it seems (I didn't test it but it has 30+ thumbs up)

Niels-75 commented 5 years ago

Thanks! Following an improved version of that script for bash. (You may need to adjust the nodejs location.) Append it to your ~/.bashrc and execute npmup in a new bash. Or, directly execute the commands of function body at once. This version actually does an update, instead of (re-)installation every time.

function npmup {
  pushd /c/Program\ Files/nodejs > /dev/null
  mv npm npm2
  mv npm.cmd npm2.cmd
  mv npx npx2
  mv npx.cmd npx2.cmd
  node node_modules/npm/bin/npm-cli.js up npm -g
  mv -n npm2 npm
  mv -n npm2.cmd npm.cmd
  mv -n npx2 npx
  mv -n npx2.cmd npx.cmd
  rm -f npm2 npm2.cmd npx2 npx2.cmd
  popd > /dev/null
}
mvarendorff commented 5 years ago

The comment I referred to has since been removed, sorry for the confusion.

hind3nbug commented 5 years ago

Using 1.1.7, I was experiencing the same issue with NPM not being copied over from the "temp" folder, when performing a fresh install of Node.js + NPM using NVM. Since I use a company machine, I am not able able to test with McAfee Endpoint Security disabled.

However, I built NVM from "master" today, and verified it is able to correctly install from scratch without issues.

matthew-dean commented 4 years ago

Note that this issue isn't just that NPM fails to install, but the NVM command-line utility also fails to recognize that NPM was not installed. IMO the installer is not doing a needed step of verifying that the directory is present, which would avoid some confusion around this issue.

matthew-dean commented 4 years ago

@hind3nbug Same for me, McAfee Endpoint Security is not disable-able on a corporate machine, so there really still needs to be a proper way to install NPM. There should be some way to do this.

javnov commented 4 years ago

Using 1.1.7, I was experiencing the same issue with NPM not being copied over from the "temp" folder, when performing a fresh install of Node.js + NPM using NVM. Since I use a company machine, I am not able able to test with McAfee Endpoint Security disabled.

However, I built NVM from "master" today, and verified it is able to correctly install from scratch without issues.

Can you share your version? I am not able to build nvm from source code :(

Shemesh commented 4 years ago

@hind3nbug & @coreybutler... so is this issue was resolved? but not released new nvm version? when a new version is estimated?

ismailkattakath commented 4 years ago

I had Nodist installed prior to nvm-windows. It left a .npmrc file under home directory (%userprofile%). I had to remove it and try nvm use command again to get everything right.

DinsmoreDesign commented 4 years ago

Had this happen to me today - uninstalling the version and then reinstalling it seemed to fix the issue.

ashleydavis commented 4 years ago

I was getting a silent failure for installation of npm.

I thought it might be the Windows virus scanner, so I disabled that: image

Strangely now the failure is not silent:

$ nvm install 12.12.0
Downloading node.js version 12.12.0 (64-bit)...
Complete
Creating C:\ProgramData\nvm\temp

Downloading npm version 6.11.3... Download failed. Rolling Back.
Rollback failed. remove C:\ProgramData\nvm\temp\npm-v6.11.3.zip: The process cannot access the file because it is being used by another process.
Could not download npm for node v12.12.0.
Please visit https://github.com/npm/npm/releases/tag/v6.11.3 to download npm.
It should be extracted to C:\ProgramData\nvm\v12.12.0
nyngwang commented 4 years ago

Did you run nvm on after the installation?

ashleydavis commented 4 years ago

Do I have to do that every time I install a new version of Node.js?

I've been using nvm for a couple of years and never had to do nvm on before.

coreybutler commented 4 years ago

I've decided to close this issue because this is starting to touch on a number of other issues. Let's stick to one issue per thread. Open a new issue if your problem is unaddressed.

I'll try to summarize based on what I've read:

1) npm will be installed by nvm. If you're seeing the old path (npm/npm), you need to upgrade NVM4W to 1.1.7. If you don't have appropriate permissions, it will fail. That's the nature and intent of Windows and why the UAC prompts exist. 2) Your Antivirus may prevent NVM4W from moving npm's files from the temp directory to it's final location. Turn it off or make an exception. See point #3. 3) NVM4W has been submitted to every major antivirus vendor and is passing (in theory). However; antivirus software changes definitions all the time, making this difficult to keep up with. Some off-brand AV base their definitions on very outdated knowledge, the most challenging being that some block go programs entirely. There was a false positive in the go runtime a few years ago.... long since been patch and NVM4W never suffered from the exploit anyway... but some AV firms block the entire go language signature. 4) Truthfully, I never turn nvm off and on. You shouldn't really have to, but it is designed to help test your system.

dtwansel commented 4 years ago

Have the same problem. This is my attempt and works for me:

  1. download the need node version from https://nodejs.org/en/download/releases/ in zip format(or other format)
  2. Delete node_modules directory if it already exist in version drectory that located in nvm install directory(eg. C:\Users\USER_NAME\AppData\Roaming\nvm\v8.11.4).
  3. unzip the file from step 1, and copy node_modules directory to version directory infered in previous step.
  4. npm works

I tried everything for two days... nvm, node re-install, restarts, PATH changes, and this is the only thing that actually worked like a charm!

smurugavels commented 4 years ago

@coreybutler can I suggest adding @liuwenzhuang 's suggestion to readme.md or Common-Issues?

This can save someone's time.

jafs commented 4 years ago

Hola, es mi caso, este mensaje en la consola me dió la pista sobre el error:

Please visit https://github.com/npm/npm/releases/tag/v6.14.4 to download npm.

Si vamos a la página https://github.com/npm/npm/, se indica que el repositorio se ha movido y que ahora está en https://github.com/npm/cli. Es decir, que habría que buscar la v6.14.4 en dicho repositorio.

rajneeshjoshi4 commented 4 years ago

I have also faced same issue on Windows 10. And it can be resolved by disabling the McAffe protection.

Open McAffe Endpoint Security > Threat Prevntion > Disable Access Protection and On access scan module (Uncheck) run > nvm install version

@coreybutler : I think you should provide some relative notification if npm not installed properly.

Joy-Joel commented 4 years ago

Have the same problem. This is my attempt and works for me:

  1. download the need node version from https://nodejs.org/en/download/releases/ in zip format(or other format)
  2. Delete node_modules directory if it already exist in version drectory that located in nvm install directory(eg. C:\Users\USER_NAME\AppData\Roaming\nvm\v8.11.4).
  3. unzip the file from step 1, and copy node_modules directory to version directory infered in previous step.
  4. npm works

Thanks @liuwenzhuang Your Comment really helped today. I have been battling with this bug for some days now

averyfreeman commented 4 years ago

Why are people downloading node from the website to use with nvm, isn't that what nvm is supposed to be for? 😉 you may as well not use nvm at all.

I had a phantom symlink nvm had created previously that it couldn't delete because of shell permissions. I'm guessing it's because I am using nvm in git bash shell as non-elevated user.

I deleted it in admin command prompt:

del /f c:\Program Files\nodejs

Then made new symlink to a version I had downloaded using nvm:

mklink /j "C:\Program Files\nodejs" "C:\Users\USER_NAME\AppData\Roaming\nvm\NODE_VERSION"

I haven't tried nvm use NODE_VERSION but there's a good chance if you delete the symlink before invoking it'll make the link for you (I'm guessing that's the expected behavior). Most likely would need to use something like this: https://github.com/imachug/win-sudo

lacroixDj commented 4 years ago

Have the same problem. This is my attempt and works for me:

  1. download the need node version from https://nodejs.org/en/download/releases/ in zip format(or other format)
  2. Delete node_modules directory if it already exist in version drectory that located in nvm install directory(eg. C:\Users\USER_NAME\AppData\Roaming\nvm\v8.11.4).
  3. unzip the file from step 1, and copy node_modules directory to version directory infered in previous step.
  4. npm works

This worked !!!

I also had the same issue with McAfee + Win 10 + PowerShell. - Many thanks @liuwenzhuang

wjhanna commented 4 years ago

Not sure why this was closed but I'm having the same issue, fresh install of Windows 10, fresh install of nvm, no Antivirus (except built-in). The official fix isn't to bypass the very reason I'm using nvm, is it?

PestoP commented 4 years ago

This comment works for me: https://github.com/coreybutler/nvm-windows/issues/475#issuecomment-538475058

Just doing nvm on... I thought it was 'on' directly after the installation 😄

onemoon commented 3 years ago

When your local npm's version is latest, it may not install the same version npm when you installing latest node, does that will happen?

Amitesh commented 3 years ago

One of my office machine has McAfee and I think it is stoping to install(copying) the npm folder. But below step comes like a rescue for me. Thanks.

Have the same problem. This is my attempt and works for me:

  1. download the need node version from https://nodejs.org/en/download/releases/ in zip format(or other format)
  2. Delete node_modules directory if it already exist in version directory that located in nvm install directory(eg. C:\Users\USER_NAME\AppData\Roaming\nvm\v8.11.4).
  3. unzip the file from step 1, and copy node_modules directory to version directory inferred in previous step.
  4. npm works

This works from me, like a charm!!

I think, Adding a testing step to confirm about the successful installation of any nodejs version through nvm-windows will be very helpful to save time. If it fails, then provide some probable insights to resolve it.

@coreybutler thought?

Thanks.

coreybutler commented 3 years ago

@Amitesh - I think having integrity checks is a good idea. However; I don't have time to do that right now (see the discussion tab, first post). I would accept a PR if someone wanted to add this.

Laxmi-laks commented 3 years ago

I'm still facing issue npm not recognized on windows 10 for newly installed node(10.23.0) using nvm (1.1.7) I followed the below steps but no use

download the need node version from https://nodejs.org/en/download/releases/ in zip format(or other format) Delete node_modules directory if it already exist in version directory that located in nvm install directory(eg. C:\Users\USER_NAME\AppData\Roaming\nvm\v8.11.4). unzip the file from step 1, and copy node_modules directory to version directory inferred in previous step. npm works can someone guide me how to get this working :( @coreybutler any help please?

nvmerror nvm npm _10 23 0
zlatinz commented 3 years ago

Just found a workaround, looking at the comments related to antivirus protection.

I am on Windows 10, 64 bit, version 1909 (build 18363.1139)

  1. From Start menu open Windows Security app.
  2. Click on Virus & Threat protection tile.
  3. In the displayed interface, choose Manage settings that is under "Virus & threat protection settings"
  4. Turn off Real-time protection
  5. From start menu, find Command Prompt, right click and "Run as Administrator"
  6. run nvm install with the version you want to install. npm will properly install now. Verify with nvm use with the version, then node -v and npm -v
  7. Go back to Windows Security app and turn real-time protection back on
TeemuKoivisto commented 3 years ago

Why are people downloading node from the website to use with nvm, isn't that what nvm is supposed to be for? 😉 you may as well not use nvm at all.

I had a phantom symlink nvm had created previously that it couldn't delete because of shell permissions. I'm guessing it's because I am using nvm in git bash shell as non-elevated user.

I deleted it in admin command prompt:

del /f c:\Program Files\nodejs

Then made new symlink to a version I had downloaded using nvm:

mklink /j "C:\Program Files\nodejs" "C:\Users\USER_NAME\AppData\Roaming\nvm\NODE_VERSION"

I haven't tried nvm use NODE_VERSION but there's a good chance if you delete the symlink before invoking it'll make the link for you (I'm guessing that's the expected behavior). Most likely would need to use something like this: https://github.com/imachug/win-sudo

After a long time not working with my Windows laptop I decided to update the Node.js version from 8 to 14. Yet I encountered the bug which I assume many others have also faced here. Your comment helped me to pinpoint the cause although your instructions didn't exactly solve my problem.

For me the issue was that nvm uses an environment variable NVM_SYMLINK which is pointed to C:\Program Files\nodejs that, as far as my installation is concerned, isn't used for installation of Node.js. Changing that to the actual installation path inside AppData\Roaming\nvm\<nodejs version> fixed the issue.

kerriganb commented 3 years ago

in case anyone is still having this issue ... this is what I did to get it to work.

(note: i had version 14.4.0 of node installed outside nvm) - after installing NVM it asked to mange 14.4.0 and i said yes ... i think this is what caused the NPM issue to not work.. ...

  1. nvm uninstall .. .in my case 14.4.0
  2. (i would nvm uninstall any versions you may have done as well ...)
  3. now you can install your version. nvm install
  4. nvm use

hopefully NPM should now work ...

lukethacoder commented 3 years ago

had similar issues with 15.7.0.

ran nvm install 15.6.0 and copied the npm folder from that install into the 15.7.0 one and works fine.

looks like certain versions dont properly install npm with nvm install