-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[BUG] using npm in windows on a wsl file mount path causes error #6280
Comments
If you run You can test this by navigating to a non UNC path in explorer, edit the address bar and type If you do the same from a UNC path, It looks like Powershell supports UNC paths, but my guess is that npm runs as a separate sub process, and the old UNC path inheritance problem still occurs. Maybe the answer here is for npm to deploy a |
Ping. Anyone from npm? |
Try this script: #!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
$nodebin = $(Get-Command "node$exe" -ErrorAction SilentlyContinue -ErrorVariable F).Source
if ($nodebin -eq $null) {
Write-Host "node$exe not found."
exit 1
}
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$nodedir/node_modules/npm/bin/npm-cli.js" $args
} else {
& "node$exe" "$nodedir/node_modules/npm/bin/npm-cli.js" $args
}
$ret=$LASTEXITCODE
exit $ret Save it in the same folder as this: $(Get-Command "npm").Source PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Ubuntu-22.04\home\test> npm --version
8.5.0 🎉 |
Resolves UNC path issues because powershell.exe supports UNC, while cmd.exe doesn't. (Which is why npm.cmd doesn't work within UNC paths, even under powershell) Resolves npm#6280
Resolves UNC path issues because powershell.exe supports UNC, while cmd.exe doesn't. (Which is why npm.cmd doesn't work within UNC paths, even under powershell) Resolves npm#6280
Resolves UNC path issues because powershell.exe supports UNC, while cmd.exe doesn't. (Which is why npm.cmd doesn't work within UNC paths, even under powershell) Resolves #6280
Resolves UNC path issues because powershell.exe supports UNC, while cmd.exe doesn't. (Which is why npm.cmd doesn't work within UNC paths, even under powershell) Resolves npm#6280
* add ps1 scripts Resolves UNC path issues because powershell.exe supports UNC, while cmd.exe doesn't. (Which is why npm.cmd doesn't work within UNC paths, even under powershell) Resolves #6280 * fixup: add tests and prefix for ps1 scripts --------- Co-authored-by: Luke Karrys <[email protected]>
I believe this has to do with how wsl is configured and not npm. The configuration file The fix for me was to disable interop in the wsl.conf config file. After you make a change to [boot]
systemd=true
[automount]
enabled=false
[interop]
enabled=false
appendWindowsPath=false |
This comment has been minimized.
This comment has been minimized.
I made your recommended changes and found out I was using my windows installation of node and npm because of wsl appending the windows path. I found out because my wsl installation told me I had to install npm and node when I tried to run them facepalm |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
This bug has been reported a number of times before (#3349, #1189) , as far back as v6 as far as I can tell.
I am not sure why, but such bug reports seem to get little to no attention from npm folks, and then eventually someone or some bot just closes the bug and says "too old, please re-open". SMH. So here I am, opening yet again.
I'm on version 9.5.1 of npm, on Windows 11.
I also have WSL2 (Debian) on this machine, which means I have a linux filesystem that windows mounts at a path like:
These paths (I guess called "UNC paths"?) work fine across Windows, in File Explorer and pretty much all windows apps I use (like Sublime, Chrome, etc).
If I go into a Windows shell (i.e., Powershell), and switch to that path, it works fine:
I can the n issue a command like this, and it works fine:
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Debian\home\my-user\tmp> node --version v19.8.1
However, if I then issue a
npm
command from that location, I get an error:As you can see, the command runs, but not in the correct working directory.
For
--version
, that's mildly annoying, but no big deal. But other commands, likenpm install
, run inC:\Windows
working directory instead of where I want them to run, which is completely broken and very bad.Obviously, the command should run in the current working directory I am in.
Expected Behavior
I expect the
npm
program to run in whatever working directory I'm in, regardless of how the (valid) path looks, without errors or (worse!) switching to another directory to run the command!As a bad (but at least reasonable) fallback, if there's just no way UNC paths could be supported (which is terrible), at a minimum these commands should just refuse to run altogether, rather than running in the wrong directory -- especially
C:\Windows
... good grief!Steps To Reproduce
\\wsl$\Debian\home\my-user\tmp
cd
to switch to that directory locationnpm install
npm install
) operates in the defaultC:\Windows
directory incorrectlyEnvironment
The text was updated successfully, but these errors were encountered: