npm-config ignores git entry

cli
help-wanted
priority:medium
triaged

(Divido) #1

What I Wanted to Do

I want to use npm to fetch resources from github, using the git executable configured in my npm-config file (.npmrc) instead of relying on searching the PATH.

What Happened Instead

[ERROR] npm ERR! code ENOGIT
[ERROR] npm ERR! Error while executing:
[ERROR] npm ERR! undefined ls-remote -h -t https://github.com/divido/karma-dojo.git
[ERROR] npm ERR!
[ERROR] npm ERR! undefined
[ERROR] npm ERR! No git binary found in $PATH
[ERROR] npm ERR!
[ERROR] npm ERR! Failed using git.
[ERROR] npm ERR! Please check if you have git installed and in your PATH.

Reproduction Steps

Move git to a weird location, specify it in the .npmrc file. Then ‘npm install’ something that has a git repository as a dependency.

Details

I configured the git executable using the .npmrc file in my home directory. It’s contents are exactly:

git = "C:\\Program Files\\Git\\bin\\git.exe"

And it seems that at least part of npm knows about it:

$ npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.4.1 node/v11.1.0 win32 x64"

; userconfig C:\Users\divido\.npmrc
git = "C:\\Program Files\\Git\\bin\\git.exe"

Head Start to Debugging

I did some digging around in the source for npm 6.4.1, and it seems that the pacote library is being used to download metadata of git repositories. From what I saw, it strictly looks on the path for the git executable, not respecting the npm-config entries. I did not see an obvious fix for the problem.

That gave me an idea, so I went digging through the NPM history, and found that pacote was introduced with version 5.0.0. A couple tests later, I see that version 5.0.0 does indeed fail the same way, while the previous version (4.6.1) works as I expected it to.

Irrelevant Context; AKA, trust me I have good reason for doing this

If you’ve read this far, I’m sure you’re asking yourself how any developer can stay sane without having git on their PATH. Well, I use cygwin for my day to day life to enjoy a reasonable command line environment. As such, my normal git activities utilize the cygwin git executable, which is aware of all the cygwin-y paths and conventions. However, node / npm do not directly support cygwin, so those use native windows executables.

To get around this, I configured NPM to use a native windows git client, which is aware of the windows-style paths that npm passes to it. I was using a fairly old instance of NPM for a while, and the .npmrc override worked like a charm – cygwin git for me via PATH, windows git for npm via .npmrc. Now I want to upgrade.

I have a workaround right now involving altering the PATH just before invoking any npm commands, but I thought that it was worth reporting that a currently documented feature of the npm-config file doesn’t work, and should be either fixed or removed.

Platform Info

$ npm --versions
{ MyProject: '0.0.0',
  npm: '6.4.1',
  ares: '1.14.0',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  modules: '67',
  napi: '3',
  nghttp2: '1.34.0',
  node: '11.1.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '7.0.276.32-node.7',
  zlib: '1.2.11' }
$ node -p process.platform
win32

(Launched from a cygwin context, though I don’t think that’s important here)


I cannot get NPM to install properly
(Lars Willighagen) #2

I made some PRs (one for npm/cli and one for zkat/pacote):