npm install -g git+file://C:\Path\To\Repository does not work on windows

What I Wanted to Do

npm install -g file://C:\Path\To\Repository

This should work, but does not. I’ve tried all combinations of slashes

What Happened Instead

# I'm using `nodeenv`, created the environment with `python -m nodeenv nenv`


C:\Users\Anthony\workspace\pre-commit>nenv\Scripts\activate.bat
(nenv) C:\Users\Anthony\workspace\pre-commit>git clone https://github.com/Jason3S/cspell
Cloning into 'cspell'...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 3060 (delta 47), reused 53 (delta 25), pack-reused 2969
Receiving objects: 100% (3060/3060), 3.43 MiB | 1.10 MiB/s, done.
Resolving deltas: 100% (2038/2038), done.

(nenv) C:\Users\Anthony\workspace\pre-commit>npm install -g git+file://C:\Users\Anthony\workspace\pre-commit\cspell
npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t file://c/Users/Anthony/workspace/pre-commit/cspell
npm ERR!
npm ERR! fatal: '//c/Users/Anthony/workspace/pre-commit/cspell' does not appear to be a git repository
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Anthony\AppData\Roaming\npm-cache\_logs\2019-02-17T19_44_30_206Z-debug.log

Reproduction Steps

See above

Details

If npm doesn’t mangle the argument, it should just work – for instance:

(nenv) C:\Users\Anthony\workspace\pre-commit>git ls-remote file://C:\Users\Anthony\workspace\pre-commit\cspell | head -5
079cd92bca8085a54e6d7bce20fd1c85bbd5834c        HEAD
079cd92bca8085a54e6d7bce20fd1c85bbd5834c        refs/heads/master
4cba8bc8ef817456b2021c096c375a76c14d33b5        refs/remotes/origin/2.x
079cd92bca8085a54e6d7bce20fd1c85bbd5834c        refs/remotes/origin/HEAD
35ad96df98656df216c6107f6dc9a29acab0dcce        refs/remotes/origin/grammar-based

Platform Info

(nenv) C:\Users\Anthony\workspace\pre-commit>npm --versions
{ npm: '6.7.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.1.1',
  modules: '67',
  napi: '4',
  nghttp2: '1.34.0',
  node: '11.10.0',
  openssl: '1.1.1a',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.26.0',
  v8: '7.0.276.38-node.17',
  zlib: '1.2.11' }

(nenv) C:\Users\Anthony\workspace\pre-commit>node -p process.platform
win32

That seems to be (in part) a Node thing:

const url = require('url') // built-in
const {href} = url.parse('git+file://C:/git') // git+file://c/git

git+file:///C:/git does parse, but I don’t know if it works.

Appears to work, so that’s a valid workaround – but the bug is still a bug ;)

I don’t know if the path is considered valid, MSDN recommends the triple-slash syntax. However, if both git and Chrome support it perhaps Node should too (not sure if it should be an npm issue).

@asottile
You might be trying to do something more complicated, but you said you wanted to:

npm install -g file://C:\Path\To\Repository

and I think this works as intended?

npm install -g C:\Path\To\Repository

@shadowspawn as I was surprised to learn as well, npm install -g $filepath and npm install -g git+file://$filepath function differently!

1 Like

(Ah, I not worked through the other thread. I wondered why you were so set on involving git. :-) )

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.