npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] git dependencies cause weird behaviour when git is not installed #7739

Closed Coding-Kiwi closed 1 month ago

Coding-Kiwi commented 2 months ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

running npm install or npm ci when git is not available causes the error

npm warn tarball tarball data for @user/package@git+https://mygitserver/user/package#hash (null) seems to be corrupted. Trying again.

which is a bit misleading in my opinion, I searched way to long for what the issue is because npm did not hint anything in that direction, not even when running with --verbose

Expected Behavior

Throw a clear error telling the user "cannot install git dependency, there is no git executable available"

Steps To Reproduce

  1. I ran inside a drone CI/CD config with the node:lts-alpine docker image which does not have git installed by default
    steps:
    - name: npm
    image: node:lts-alpine
    commands:
      - npm ci
  2. install the package (I used npm i -D git+https://myrepo.com/user/repo.git#hash)
  3. run npm ci in pipeline
  4. get error about tarball
  5. add apk add --no-cache git to the pipeline script and it works

Environment

prefix = "C:\Users\MyUser\AppData\Roaming\npm"

; node bin location = C:\Program Files\nodejs\node.exe ; node version = v20.16.0 ; npm local prefix = C:\ ; npm version = 10.8.2 ; cwd = C:\ ; HOME = C:\Users\MyUser ; Run npm config ls -l to show all defaults.

milaninfy commented 2 months ago

Generally you should have git installed if you are using the git dependencies https://docs.npmjs.com/cli/v10/commands/npm-doctor#checking-for-git-executable-in-path

When running npm install, it does say that git can not be spawn

/app # npm install https://github.com/npm/promise-spawn.git
npm error code ENOENT
npm error syscall spawn git
npm error path git
npm error errno -2
npm error enoent An unknown git error occurred
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-08-26T15_55_15_629Z-debug-0.log
milaninfy commented 1 month ago

Not able to reproduce the issue and come to the exact error mentioned in the report. Closing as I believe it's not an issue as npm cli as npm requires git to be installed.