npm / npm/cli

[BUG] Installing a package globally from a git repo does not make any dependencies available during prepare script

Open
#8,440 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues

This issue touched on multiple things, and ended up closed: https://github.com/npm/cli/issues/1865

But, it seems evident that this particular problem was never resolved.

This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

The docs state this about the "prepare" script:

NOTE: If a package being installed through git contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.

This is evidently not true:

% npm install --include=dev -g "https://github.com/backtrace-labs/backtrace-morgue.git#cstrahan/test" --foreground-scripts

up to date in 232ms
npm error code 127
npm error git dep preparation failed
npm error command /Users/charles.strahan/.local/share/mise/installs/node/24.4.0/bin/node /Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/charles.strahan/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm error > backtrace-morgue@1.24.11 prepare
npm error > npm run build
npm error
npm error
npm error > backtrace-morgue@1.24.11 build
npm error > npm run clean && npm run compile
npm error
npm error
npm error > backtrace-morgue@1.24.11 clean
npm error > tsc -b --clean
npm error npm warn using --force Recommended protections disabled.
npm error npm warn using --force Recommended protections disabled.
npm error npm warn using --force Recommended protections disabled.
npm error sh: tsc: command not found
npm error npm error code 127
npm error npm error path /Users/charles.strahan/.npm/_cacache/tmp/git-clonePcQvUY
npm error npm error command failed
npm error npm error command sh -c npm run build
npm error npm error A complete log of this run can be found in: /Users/charles.strahan/.npm/_logs/2025-07-17T22_30_03_974Z-debug-0.log
npm error A complete log of this run can be found in: /Users/charles.strahan/.npm/_logs/2025-07-17T22_29_57_297Z-debug-0.log

Note the sh: tsc: command not found.

I have a project written in typescript, and I need to run the compiler in the prepare script in order to have the *.js source generated, otherwise installing from git (e.g. npm install -g "https://github.com/backtrace-labs/backtrace-morgue.git#cstrahan/test) will result in a broken package being installed.

I have tried with several versions of node (including node installed through brew) and their bundled npm, including the latest of each, and I have not seen the desired, advertised behavior.

% npm --version                                                                                                                                               
11.4.2
% node --version
v24.4.0
Expected Behavior

As stated in the docs, the packages listed in "dependencies" and "devDependencies" should be available in the installation environment during the prepare script.

Steps To Reproduce
  1. In this environment...
  2. With this config...
  3. Run '...'
  4. See error...
Environment
  • npm: 11.4.2
  • Node.js: v24.4.0
  • OS Name: macOS
  • System Model Name:
  • npm config:
; "builtin" config from /opt/homebrew/lib/node_modules/npm/npmrc

prefix = "/opt/homebrew"

; node bin location = /opt/homebrew/Cellar/node/24.3.0/bin/node
; node version = v24.3.0
; npm local prefix = /Users/charles.strahan
; npm version = 11.4.2
; cwd = /Users/charles.strahan
; HOME = /Users/charles.strahan
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the global git installation with npm 11.4.2 and the backtrace-morgue repository, using --foreground-scripts, and observe whether dependencies are available to prepare. Trace npm's git dependency preparation path and verify completion when the prepare script can run tsc from the installed dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.