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

[BUG] npm breaks on Windows when running off a UNC path #1189

Closed
Stanzilla opened this issue Apr 21, 2020 · 6 comments
Closed

[BUG] npm breaks on Windows when running off a UNC path #1189

Stanzilla opened this issue Apr 21, 2020 · 6 comments
Labels
Bug thing that needs fixing platform:windows is Windows-specific Release 6.x work is associated with a specific npm 6 release

Comments

@Stanzilla
Copy link

Stanzilla commented Apr 21, 2020

What / Why

Currently when trying to use npm to install a project on UNC path, like WSL, it fails because it tries to use cmd.exe which does not support UNC paths.

When

I run npm install

Where

On a WSL / UNC share

How

Current Behavior

PS Microsoft.PowerShell.Core\FileSystem::\wsl$\Ubuntu\home\stan\projects\personal\WeakAurasCompanion> npm install
'\wsl$\Ubuntu\home\stan\projects\personal\WeakAurasCompanion'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
npm WARN saveError ENOENT: no such file or directory, open 'C:\Windows\package.json'
npm WARN saveError EPERM: operation not permitted, open 'C:\Windows\package-lock.json.415733530'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Windows\package.json'

Steps to Reproduce

Run npm install on a UNC path / WSL

Expected Behavior

  • install works

Who

  • n/a

References

@Stanzilla
Copy link
Author

Still broken on 6.14.4

@darcyclarke darcyclarke added Release 6.x work is associated with a specific npm 6 release platform:windows is Windows-specific Bug thing that needs fixing labels Oct 30, 2020
@felipecrs
Copy link
Contributor

Actually, still broken as of now (v7.7.6).

Refs volta-cli/volta#966.

@Stanzilla
Copy link
Author

Also refs #2699

@felipecrs
Copy link
Contributor

felipecrs commented Apr 10, 2021

I was thinking about this issue, and I was able to successfully generate a shim for npm whichs work around this issue. It's based on kiennq/scoop-better-shimexe#1. Demo:

Fails with npm.cmd

 \\wsl$\ubuntu\home\felipecrs\repos\megatar :: git(master ↓2  ~4)                                                                                        [  ] 19:14:21C:\Users\felip\AppData\Local\Volta\tools\image\npm\7.9.0\bin\npm.cmd show . name
'\\wsl$\ubuntu\home\felipecrs\repos\megatar'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Windows\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Windows\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\felip\AppData\Local\npm-cache\_logs\2021-04-10T22_14_29_514Z-debug.log

Works with the shim I generated, npm.exe

 \\wsl$\ubuntu\home\felipecrs\repos\megatar :: git(master ↓2  ~4)                                                                                        [  ] 19:13:41C:\Users\felip\AppData\Local\Volta\tools\image\npm\7.9.0\bin\npm.exe show . name
megatar

Contents of npm.shim

 \\wsl$\ubuntu\home\felipecrs\repos\megatar :: git(master ↓2  ~4)                                                                                        [  ] 19:14:29cat C:\Users\felip\AppData\Local\Volta\tools\image\npm\7.9.0\bin\npm.shim
path = node.exe
args = %~dp0\npm-cli.js

I'm working on a module which would facility for such shims to be created when publishing npm packages, https://github.com/felipecrs/win-bin-gen, but I'm still not sure if I should proceed with this approach or no.

Anyway, this is a potential fix for the issue in the npm CLI, and the npm.exe (not yet optimized), has around 200KB.

There is also another good thing about this approach, which is that shims specifically for Git Bash/Cygwin would probably not be needed anymore.

@felipecrs
Copy link
Contributor

I would like to extend this bug coverage a bit:

  • This happens with any module installed by NPM on Windows, as stated in the issue description
  • This happens with NPM itself, as its executable is npm.cmd

@darcyclarke
Copy link
Contributor

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is preproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing platform:windows is Windows-specific Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

No branches or pull requests

3 participants