Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't install NPM #766

Closed
ddcado opened this issue Mar 1, 2022 · 29 comments
Closed

Doesn't install NPM #766

ddcado opened this issue Mar 1, 2022 · 29 comments

Comments

@ddcado
Copy link

ddcado commented Mar 1, 2022

I use nvm to install node on windows as recommanded by microsoft.
After, npm wasn't install.
I saw that the npm mirror by default is "https://github.com/npm/cli/archive/" but this page doen't exist any more "err 404 not found"
I don't know what is the good uri....
I finally used node.js msi from the node js.com.
Kind regards.

@coreybutler
Copy link
Owner

Are you using an old version of NVM4W? This was fixed in version 1.1.7 (and above).

@ddcado
Copy link
Author

ddcado commented Mar 1, 2022

1.1.
Capture
9

@tchari
Copy link

tchari commented Mar 1, 2022

I have the same issue.

I take it back. I had not installed my node version first.

@ddcado I did
nvm --version (check it's 1.1.9)
nvm install 16.14.0
nvm use 16.14.0
node --version (verify its v16.14.0)
npm --version (I got 8.3.1)

@ddcado
Copy link
Author

ddcado commented Mar 1, 2022

You have to :
nvm list available
nvm install 16.14.0
After try nvm list
Et nvm -v

@WORMSS
Copy link
Contributor

WORMSS commented Mar 2, 2022

Are you using an old version of NVM4W? This was fixed in version 1.1.7 (and above).

@coreybutler I have found that 1.1.9 does not install npm though 1.1.7 does.

nvm 1.1.7

C:\WINDOWS\system32>nvm uninstall 17.6.0
Uninstalling node v17.6.0... done
C:\WINDOWS\system32>nvm install 17.6.0
Downloading node.js version 17.6.0 (64-bit)...
Complete
Creating C:\Users\CRichardson\AppData\Roaming\nvm\temp

Downloading npm version 8.5.1... Complete
Installing npm v8.5.1...

Installation complete. If you want to use this version, type

nvm use 17.6.0

nvm 1.1.9

C:\WINDOWS\system32>nvm uninstall 17.4.0
Uninstalling node v17.4.0... done
C:\WINDOWS\system32>nvm install 17.4.0
Downloading node.js version 17.4.0 (64-bit)...
Extracting...
Complete


Installation complete. If you want to use this version, type

nvm use 17.4.0

No "Downloading npm"

@xuke-hat
Copy link

xuke-hat commented Mar 6, 2022

I have the same issue.

@github-actions
Copy link

github-actions bot commented Apr 6, 2022

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Stale label Apr 6, 2022
@WORMSS
Copy link
Contributor

WORMSS commented Apr 6, 2022

Stale because noone has fixed it, not because noone wants it fixed.

@github-actions github-actions bot removed the Stale Stale label Apr 7, 2022
@thengoster
Copy link

thengoster commented Apr 7, 2022

@WORMSS The "Downloading npm" message does not appear because web.go added additional logic to the GetNodeJS function from v1.1.7 -> v1.1.9, where the additions can be seen in the else block snippet:

nvm-windows/src/web/web.go

Lines 139 to 186 in f792f4e

if url == "" {
//No url should mean this version/arch isn't available
fmt.Println("Node.js v" + v + " " + a + "bit isn't available right now.")
} else {
fileName := root + "\\v" + v + "\\node" + a + ".exe"
if strings.HasSuffix(url, ".zip") {
fileName = root + "\\v" + v + "\\node.zip"
}
fmt.Println("Downloading node.js version " + v + " (" + a + "-bit)... ")
if Download(url, fileName, v) {
// Extract the zip file
if strings.HasSuffix(url, ".zip") {
fmt.Println("Extracting...")
err := unzip(fileName, root+"\\v"+v)
if err != nil {
fmt.Println("Error extracting from Node archive: " + err.Error())
err = os.Remove(fileName)
if err != nil {
fmt.Printf("Failed to remove %v after failed extraction. Please remove manually.", fileName)
}
return false
}
err = os.Remove(fileName)
if err != nil {
fmt.Printf("Failed to remove %v after successful extraction. Please remove manually.", fileName)
}
zip := root + "\\v" + v + "\\" + strings.Replace(filepath.Base(url), ".zip", "", 1)
err = fs.Move(zip, root+"\\v"+v, true)
if err != nil {
fmt.Println("ERROR moving file: " + err.Error())
}
err = os.RemoveAll(zip)
if err != nil {
fmt.Printf("Failed to remove %v after successful extraction. Please remove manually.", zip)
}
}
fmt.Printf("Complete\n")
return true
} else {
return false
}

Lines 144 and 152 check if the url has the .zip suffix, and if it does, then the function will extract both NodeJS and npm. The code to determine the node url is in getNodeUrl:

nvm-windows/src/web/web.go

Lines 253 to 275 in f792f4e

func getNodeUrl(v string, vpre string, arch string, append bool) string {
a := "x86"
if arch == "64" {
a = "x64"
}
//url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
url := GetFullNodeUrl("v" + v + "/" + vpre + "/node.exe")
if !append {
version, err := semver.Make(v)
if err != nil {
fmt.Println("Node.js v" + v + " " + a + "bit isn't available right now.")
fmt.Println(err.Error())
os.Exit(1)
}
corepack, _ := semver.Make("16.9.0")
if version.GTE(corepack) {
url = GetFullNodeUrl("v" + v + "/node-v" + v + "-win-" + a + ".zip")
}
}

Lines 263-274 shows that if the node version we are trying to download is >= corepack (here it is 16.9.0), then we will change the url to incorporate the aforementioned zip file.

Here are screenshots detailing this in action and verifying that npm is still being installed for node.js versions >= 16.9.0

v16.8.0 test
install_16 8 0

v17.4.0 test
install_17 4 0

npm installs fine on both node.js versions, but a message that signals to the user that npm is in fact actually being installed would be useful!

@WORMSS
Copy link
Contributor

WORMSS commented Apr 7, 2022

Yeah, just too many things are weird in 1.18 and higher. Things just not working and so on..
I've found it easier to just stay on 1.17. I've not seen a reason to upgrade yet. No functionality added, just bugs.

@baybars1223
Copy link

baybars1223 commented Apr 15, 2022

EDIT: Closing and reopening the command prompt terminal seems to have resolved the issue for me
EDIT 2: When the computer was restarted, the issue reappeared. Once again, closing and reopening the terminal resolved the issue (temporarily at least).

It seems to be an issue of nvm not 'switching' rather than not installing. On nvm 1.1.9, npm is 'stuck' at 6.12.0 no matter which version I install or use. But if you navigate to %APPDATA%\nvm\v16.14.2\node_modules\npm, for example, the correct version is present.

Log of attempts to uninstall/reinstall:

C:\Users\XXX>nvm use 16.14.2
Now using node v16.14.2 (64-bit)

C:\Users\XXX>npm -v
6.12.0

C:\Users\XXX>nvm install latest
Downloading node.js version 17.9.0 (64-bit)...
Extracting...
Complete


Installation complete. If you want to use this version, type

nvm use 17.9.0

C:\Users\XXX>npm -v
6.12.0

C:\Users\XXX>nvm list

    17.9.0
  * 16.14.2 (Currently using 64-bit executable)
    12.13.1

C:\Users\XXX>nvm uninstall 17.9.0
Uninstalling node v17.9.0... done
C:\Users\XXX>nvm list

  * 16.14.2 (Currently using 64-bit executable)
    12.13.1

C:\Users\XXX>nvm install latest
Downloading node.js version 17.9.0 (64-bit)...
Extracting...
Complete


Installation complete. If you want to use this version, type

nvm use 17.9.0

C:\Users\XXX>nvm use 17.9.0
Now using node v17.9.0 (64-bit)

C:\Users\XXX>node -v
v17.9.0

C:\Users\XXX>npm -v
6.12.0

C:\Users\XXX>nvm uninstall 12.13.1
Uninstalling node v12.13.1... done
C:\Users\XXX>nvm uninstall 16.14.2
Uninstalling node v16.14.2... done
C:\Users\XXX>npm -v
6.12.0

C:\Users\XXX>nvm install 12.13.1
Downloading node.js version 12.13.1 (64-bit)...
Complete
Creating C:\Users\XXX\AppData\Roaming\nvm\temp

Downloading npm version 6.12.1... Complete
Installing npm v6.12.1...

Installation complete. If you want to use this version, type

nvm use 12.13.1

C:\Users\XXX>nvm use 12.13.1
Now using node v12.13.1 (64-bit)

C:\Users\XXX>node -v
v12.13.1

C:\Users\XXX>npm -v
6.12.0

C:\Users\XXX>nvm install 16.14.2
Downloading node.js version 16.14.2 (64-bit)...
Extracting...
Complete


Installation complete. If you want to use this version, type

nvm use 16.14.2

C:\Users\XXX>nvm use 16.14.2
Now using node v16.14.2 (64-bit)

C:\Users\XXX>node -v
v16.14.2

C:\Users\XXX>npm -v
6.12.0

@xujimu
Copy link

xujimu commented Apr 17, 2022

The problem remains unresolved

@douglasg14b
Copy link

douglasg14b commented May 11, 2022

This is still an issue, NPM is not installed... Which kind of, completely, breaks things.

on 1.1.9 no erorrs, just doesn't try and install NPM at all.

On 1.1.8 it seems to try, and fail:

Downloading npm version 6.14.17... Download failed. Rolling Back.
Rollback failed. remove C:\Users\Douglas.Gaskell\AppData\Roaming\nvm\temp\npm-v6.14.17.zip: The process cannot access the file because it is being used by another process.
Could not download npm for node v14.19.2.
Please visit https://github.com/npm/cli/releases/tag/v6.14.17 to download npm.
It should be extracted to C:\Users\Douglas.Gaskell\AppData\Roaming\nvm\v14.19.2

NVM will always say there is another process accessing the file, even after a fresh restart. I can freely go in and delete it.

Unfortunately there are no builds at https://github.com/npm/cli/releases/tag/v6.14.17 just source code bundles... If I extract that into the dir as instructed, it still does not work. If I copy the executables from \bin into the \v14.19.2 directory, running npm just throws errors about being unable to find 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'

There is no npm executable in the install dir:

image

@douglasg14b
Copy link

Has anyone gotten this working on their device? If so, how?

@douglasg14b
Copy link

douglasg14b commented May 11, 2022

It's probably failing to install because the download fails, because this path: https://github.com/npm/cli/archive/v6.14.17.zip

Returns: the given path has multiple possibilities: #<Git::Ref:0x00007f10c0794050>, #<Git::Ref:0x00007f10c0756548> instead of a zip file.

@mrtawil
Copy link

mrtawil commented May 12, 2022

This is still an issue, NPM is not installed... Which kind of, completely, breaks things.

on 1.1.9 no erorrs, just doesn't try and install NPM at all.

On 1.1.8 it seems to try, and fail:

Downloading npm version 6.14.17... Download failed. Rolling Back.
Rollback failed. remove C:\Users\Douglas.Gaskell\AppData\Roaming\nvm\temp\npm-v6.14.17.zip: The process cannot access the file because it is being used by another process.
Could not download npm for node v14.19.2.
Please visit https://github.com/npm/cli/releases/tag/v6.14.17 to download npm.
It should be extracted to C:\Users\Douglas.Gaskell\AppData\Roaming\nvm\v14.19.2

NVM will always say there is another process accessing the file, even after a fresh restart. I can freely go in and delete it.

Unfortunately there are no builds at https://github.com/npm/cli/releases/tag/v6.14.17 just source code bundles... If I extract that into the dir as instructed, it still does not work. If I copy the executables from \bin into the \v14.19.2 directory, running npm just throws errors about being unable to find 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'

There is no npm executable in the install dir:

image

Same issue

@coreybutler
Copy link
Owner

The process cannot access the file because it is being used by another process. is caused by the OS locking a directory. This can be caused by any application using one of the executables in the directory (like a running process). This can also be caused by being in the directory that you're trying to change to/from on the terminal.

For example, if NVM4W is installed at C:\nvm4w, then Node 16.14.2 will be installed in C:\nvm4w\v16.14.2. If you open a terminal and cd to C:\nvm4w\v16.14.2 and try to run nvm use x.x.x, Windows will lock the directory that's open in the terminal. This creates a conflict when trying to change the symlink. This isn't necessarily the case for everyone in this thread. I'm just pointing out the error message originates from the OS.

In the case of npm 6.14.2, it's just a bad link (as @douglasg14b pointed out). See #799.

@pedroyan
Copy link

pedroyan commented May 13, 2022

Hi folks,

I came across this issue and none of the other suggestions were working, such as Enabling Developer Mode or running NVM from a privileged prompt.

image

What fixed it for me was downgrading NVM to 1.1.7. Hopefully this might also help you too.

Edit: scratch that - What worked was installing node 14.0.0. For some reason, when you try to run NVM Install on that version you get no errors.

I will try to see how high I can go without problems and post back here my findings

@pedroyan
Copy link

pedroyan commented May 13, 2022

Ok, just finished my experiment. The NPM Install problem begins when trying to install Node v14.19.2. Installing Node v14.19.1 with NVM works without problems. I ran this experiment on NVM 1.1.7


PS C:\Users\pedro> nvm install 14.19.2
Downloading node.js version 14.19.2 (64-bit)...
Complete
Creating C:\Users\pedro\AppData\Roaming\nvm\temp

Downloading npm version 6.14.17... Download failed. Rolling Back.
ause it is being used by another process.
Could not download npm for node v14.19.2.
Please visit https://github.com/npm/cli/releases/tag/v6.14.17 to download npm.
It should be extracted to C:\Users\pedro\AppData\Roaming\nvm\v14.19.2


PS C:\Users\pedro> nvm uninstall 14.19.2
Uninstalling node v14.19.2... done


PS C:\Users\pedro> nvm install 14.19.2
Downloading node.js version 14.19.2 (64-bit)...
Complete
Creating C:\Users\pedro\AppData\Roaming\nvm\temp
Downloading npm version 6.14.17... Download failed. Rolling Back.
Rollback failed. remove C:\Users\pedro\AppData\Roaming\nvm\temp\npm-v6.14.17.zip: The process cannot access the file because it is being used by another process.
Could not download npm for node v14.19.2.
Please visit https://github.com/npm/cli/releases/tag/v6.14.17 to download npm.
It should be extracted to C:\Users\pedro\AppData\Roaming\nvm\v14.19.2


PS C:\Users\pedro> nvm install 14.18.3
Downloading node.js version 14.18.3 (64-bit)...
Complete
Creating C:\Users\pedro\AppData\Roaming\nvm\temp
Downloading npm version 6.14.15... Complete
Installing npm v6.14.15...

Installation complete. If you want to use this version, type

nvm use 14.18.3


PS C:\Users\pedro> nvm install 14.19.0
Downloading node.js version 14.19.0 (64-bit)...
Complete
Creating C:\Users\pedro\AppData\Roaming\nvm\temp

Downloading npm version 6.14.16... Complete
Installing npm v6.14.16...

Installation complete. If you want to use this version, type

nvm use 14.19.0


PS C:\Users\pedro> nvm install 14.19.1
Downloading node.js version 14.19.1 (64-bit)...
Complete
Creating C:\Users\pedro\AppData\Roaming\nvm\temp

Downloading npm version 6.14.16... Complete
Installing npm v6.14.16...

Installation complete. If you want to use this version, type

nvm use 14.19.1


PS C:\Users\pedro> nvm install 14.19.2
Downloading node.js version 14.19.2 (64-bit)...
Complete
Creating C:\Users\pedro\AppData\Roaming\nvm\temp

Downloading npm version 6.14.17... Download failed. Rolling Back.
Rollback failed. remove C:\Users\pedro\AppData\Roaming\nvm\temp\npm-v6.14.17.zip: The process cannot access the file because it is being used by another process.
Could not download npm for node v14.19.2.
Please visit https://github.com/npm/cli/releases/tag/v6.14.17 to download npm.
It should be extracted to C:\Users\pedro\AppData\Roaming\nvm\v14.19.2
PS C:\Users\pedro>

@Herr-Sepp
Copy link

Herr-Sepp commented May 17, 2022

I can confirm pedroyan observations.

nvm 1.1.9
Windows Server 2019

14.19.1 works
14.19.2:

nvm install 14.19.2

Downloading node.js version 14.19.2 (64-bit)...
Complete
Downloading npm version 6.14.17... Download failed. Rolling Back.
Rollback failed. remove C:\Program Files\nvm\temp\npm-v6.14.17.zip: Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird.
Could not download npm for node v14.19.2.
Please visit https://github.com/npm/cli/releases/tag/v6.14.17 to download npm.
It should be extracted to C:\Program Files\nvm\v14.19.

@yoavain
Copy link

yoavain commented May 19, 2022

Problem is that the URL https://github.com/npm/cli/archive/v6.14.7.zip results in status code 302, which redirects to https://codeload.github.com/npm/cli/zip/refs/tags/v6.14.7 (see location header).
The root cause is that the Download function does not follow this redirect. It fails on any status code other than 200.

@yoavain
Copy link

yoavain commented May 20, 2022

The second problem is that this tool is written in Go, and most of the developers looking for a fix are NodeJS developers.
Unfortunately, I currently don't have the time to learn Go to offer help.

@IlCallo
Copy link

IlCallo commented May 25, 2022

Can confirm the URL problem seems to be the real culprit

@Kanyan88
Copy link

Kanyan88 commented May 28, 2022

you can check that NPM is installed with the version you chose to install from this directory C:\Users\%USERNAME%\AppData\Roaming\nvm
the directories with v prefix are the install versions you can check npm exsist inside npm modules
for people who installed for the first time you should :
run cmd as Admin then list versions with nvm list then nvm use __version_number__ otherwise nvm will not be using any installation you downloaded

@coreybutler
Copy link
Owner

coreybutler commented May 28, 2022

The issue was the URL. When a Github project has a branch and a tag with the same name, Github returns an HTTP status 300, not a redirect . If NVM4W encounters a status like this, it will now output the results to screen:

image

There is also a specific error handler to work around this particular version of npm, since it appears to be the only version affected by this problem. If the invalid URL for npm 6.14.17 is detected, NVM4W will automatically rewrite the URL to the appropriate endpoint. I am not fond of these kinds of hacks, since they are brittle and can break again if the upstream endpoint changes again.

This will be a part of v1.1.10, which will be released after I've had a chance to incorporate a few more PRs.

@ArclightRSA
Copy link

ArclightRSA commented Jun 7, 2022

Okay I am not sure if it has been mentioned, but I have a workaround for now...

Rename the two folders npm and npm-cache in C:\Users\MyUsername\AppData\Roaming to anything you desire, this will induce a rollback function.

My experience

I found that C:\Users\MyUsername\AppData\Roaming has two folders npm and npm-cache. I renamed them to npm.1 and npm-cache,1. This gives me access to npm again. What I am suspecting and correct me if I am wrong the roaming folder is where my global settings are stored as I noticed when I rename those folders it then looks at my Program Files Node folder.

I have multiple projects running atm that requires met to switch between Node 10.16.0, 10.18.0 and 16 hence why I would like to just understand why this work around is working. When I switch between 10.18.0 and 16 and 18 I can use npm but when I switch back to 10.16 I had to redo the rename workaround.

I hope this helps someone in dire need like it helped me as I have access to my different versions in nvm and access to npm

@coreybutler
Copy link
Owner

For those finding this issue for npm 6.14.17, there was an issue upstream in the npm github reo that has been fixed: npm/cli#4890 (comment).

coreybutler added a commit that referenced this issue Oct 31, 2022
@bengabp
Copy link

bengabp commented Jul 9, 2024

and i have thesame issue now

@WORMSS
Copy link
Contributor

WORMSS commented Jul 9, 2024

and i have thesame issue now

This has not been a issue for many years. If you have all the latest version's of NVM, it would be worth creating a new issue with all the relevant information such as OS/NVM version/paths trying to use/etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests