[BUG] npm doesn't quote the path used when running Git to clone a repository during package install #2414
Labels
Bug
thing that needs fixing
platform:windows
is Windows-specific
Release 7.x
work is associated with a specific npm 7 release
Current Behavior:
Running
npm install
on a project with a dependency (or transitive dependency) on a GitHub repo (an example of which can be found here) will lead to an error caused by Git during the cloning process.Click to see the CLI output demonstrating the error
Expected Behavior:
Running
npm install
on a project with a dependency (or transitive dependency) on a GitHub repo should successfully install the dependencies and exit without error.Explanation:
The error from Git happens because the path that the repository will be cloned into contains spaces. In my case, because Windows configured my home directory to be
C:\Users\Ryan Cloherty
, Git can't clone into this folder and fails when it gets told to do so by npm.The command that npm runs (in my case, given that I want to use the package "discord-rpc") is
git clone ssh://[email protected]/devsnek/node-register-scheme.git C:\Users\Ryan Cloherty\AppData\Local\npm-cache\_cacache\tmp\git-clone-c66c9a05 --recurse-submodules --depth=1 --config core.longpaths=true
. Running this same command in Git Bash yields the same "too many arguments" error. However, quoting the path like sogit clone ssh://[email protected]/devsnek/node-register-scheme.git "C:\Users\Ryan Cloherty\AppData\Local\npm-cache\_cacache\tmp\git-clone-c66c9a05" --recurse-submodules --depth=1 --config core.longpaths=true
will clone the repo successfully.Steps To Reproduce:
npm install
.Workaround:
To work around this issue, you can change the directory that "npm-cache" will be kept to some other path without spaces. I chose to just dump the "npm-cache" folder at the root of my C drive. You can edit the various directories that npm uses via
npm config edit
much like what was seen in another path-related issue. Uncomment the "cache" line and change the directory to some folder without spaces. I chose to usecache=C:\npm-cache
. Save and close the config file and try runningnpm install
again. It should work just fine.Side note: The package I was trying to install is discord-rpc. If you don't have Visual Studio C++ related stuff installed, the install will fail. However, that particular error is unrelated to the Git error and if you've gotten to the Visual Studio-related error, you've passed the point at which the Git error should have occurred.
Environment:
%USERPROFILE%
) with one or more spaces in itThe text was updated successfully, but these errors were encountered: