Reputation: 222344
Versioned package doesn't run with npx
(npm exec
) when the package has already been installed globally with npm. The environment is Windows 10, Node 16, NPM 8.
npx npm@6 -v
results in output:
Need to install the following packages:
npm@6
Ok to proceed? (y) y
8.5.2
Subsequent npx npm@6 -v
call skips the installation to cache and runs globally installed package. Same for other global packages. I can verify that correct package versions are installed to npm-cache/_npx
but not sure what happens with them next
I believe this has been changed since NPM 6, npx
cache is used
I wonder what happens inside. Is it a known issue? Any workarounds to run versioned global packages while keeping the default one installed?
Upvotes: 2
Views: 1145
Reputation: 3738
To fix this issue, you can run the command under WSL (Windows Subsystem for Linux). The reason for this is because there might be a bug in Windows.
To install WSL, you can follow the following steps.
Make sure you are running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11. To check this, you can open Run (using Windows + R), and typing winver
. You can check the version here.
See the GIF below for a visual representation of how to do it.
This GIF was made in a Windows 7 virtual machine.
Run the following command in PowerShell or Command Prompt (running as administrator).
$ wsl --install
This should restart your machine, and add the Ubuntu distribution to WSL 2.
For more information on the installation steps, see Microsoft's official page.
Running the commands in WSL should help resolve the issue.
$ npx npm@6 -v
Upvotes: 1
Reputation: 829
i have not been able to reproduce this under linux. (using npm/npx v. 8.5.5)
> npx npm@6 -v
Need to install the following packages:
npm@6
Ok to proceed? (y) y
6.14.16
maybe the issue fixes itself if you update, but i could also be a bug in the windows implementation of npm.
for the time being you could also try to run your program under WSL (windows subsystem for linux).
i am sorry for this somewhat unpleasing answer, but i also couldn't find any better reason for this issue
Upvotes: 1