coreybutler / nvm-windows

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

NVM assumes node installed after failed installation #303

Open kumarharsh opened 7 years ago

kumarharsh commented 7 years ago

My Environment

I'm using NVM4W version:

I have already...

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

I tried upgrading node to 8.5.0 today on my nvm1.1.1 + powershell + Windows10 Creators Update machine. I put in nvm install 8.5.0 in the terminal. Incidentally, my net connection was acting up, so the laptop dropped the connection just when I pressed enter. NVM showed an error after some time:

Downloading node.js version 8.5.0 (64-bit)... Error while downloading https://nodejs.org/dist/v8.5.0/win-x64//node.exe - read tcp 192.168.2.112:4889->104.20.23.46:443: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Complete
Creating C:\Users\kumar\AppData\Roaming\nvm\temp

Downloading npm version 5.3.0... Error while downloading https://github.com/npm/npm/archive/v5.3.0.zip - Get https://codeload.github.com/npm/npm/zip/v5.3.0: dial tcp: lookup codeload.github.com: getaddrinfow: No such host is known.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x0 pc=0x496460]

goroutine 1 [running]:
panic(0x6eb740, 0x12e62030)
        C:/Go/src/runtime/panic.go:481 +0x326
_/C_/Users/Corey/Documents/workspace/nvm-windows/src/nvm/web.Download(0x13041f80, 0x2d, 0x12efe5c0, 0x36, 0x0)
        C:/Users/Corey/Documents/workspace/nvm-windows/src/nvm/web/web.go:64 +0xab0
_/C_/Users/Corey/Documents/workspace/nvm-windows/src/nvm/web.GetNpm(0x12e429f1, 0x22, 0x131fa380, 0x5, 0x2)
        C:/Users/Corey/Documents/workspace/nvm-windows/src/nvm/web/web.go:144 +0x43b
main.install(0x12e4c0f0, 0x5, 0x729a48, 0x2)
        C:/Users/Corey/Documents/workspace/nvm-windows/src/nvm.go:221 +0x11dc
main.main()
        C:/Users/Corey/Documents/workspace/nvm-windows/src/nvm.go:67 +0xde8

After that, I ran the install script again, and got a little surprise:

$> nvm install 8.5.0
Version 8.5.0 is already installed.

What?

Then, I tried switching to this version of node, and check it's version:

$> node --version
Can't create process, ErrCode=0x000000C1, Description:
%1 is not a valid Win32 application.

Current directory:
C:\Workspace

Command to be executed:
"C:\Program Files\nodejs\node.exe" --version

So, I go to the nvm cache folder in C:\Users\kumar\AppData\Roaming\nvm\v8.5.0, and it seems that the node.exe file is only 1MB, whereas the actual node.exe filesize for 7.8.0 is about 20MB. Seems like a borked installation.

Expected Behavior

NVM should gracefully handle failed installs.

Actual Behavior

Broken node version installed.

Steps to reproduce the problem:

  1. Run nvm install x.x.x
  2. Disconnect internet
  3. nvm might fail, but show the version as installed.
coreybutler commented 7 years ago

Try updating NVM4W. Alot of fixes happened after v1.1.1.

gera2ld commented 6 years ago

Same issue with NVM4W v1.1.6. The downloading fails and the file is broken, but shown as installed.

I think it should be downloaded as a temporary file and renamed to node.exe only if downloaded successfully. Currently even the file is broken, it's named node.js and prevents a re-installation.