Skip to content

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

Open

Description

@cstrahan

Is there an existing issue for this?

  • I have searched the existing issues

This issue touched on multiple things, and ended up closed: #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.

Activity

  1. cstrahan commented on Jul 17, 2025

    @cstrahan
    Author

    Okay, installing without -g works as expected:

    % npm install "https://github.com/backtrace-labs/backtrace-morgue.git#cstrahan/test" --foreground-scripts 
    
    > backtrace-morgue@1.24.11 prepare
    > tsc && npm run copy-assets
    
    
    > backtrace-morgue@1.24.11 copy-assets
    > cp -r assets dist/
    
    
    added 1 package, and audited 540 packages in 12s
    
    37 packages are looking for funding
      run `npm fund` for details
    
    found 0 vulnerabilities
    

    but it doesn't work with -g:

    % npm install -g "https://github.com/backtrace-labs/backtrace-morgue.git#cstrahan/test" --foreground-scripts
    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 > tsc && npm run copy-assets
    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-clone8uOUgo
    npm error npm error command failed
    npm error npm error command sh -c tsc && npm run copy-assets
    npm error npm error A complete log of this run can be found in: /Users/charles.strahan/.npm/_logs/2025-07-17T23_06_46_036Z-debug-0.log
    npm error A complete log of this run can be found in: /Users/charles.strahan/.npm/_logs/2025-07-17T23_06_40_604Z-debug-0.log
    

    and here's the log file:

    0 verbose cli /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
    1 info using npm@11.4.2
    2 info using node@v24.4.0
    3 silly config load:file:/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/npmrc
    4 silly config load:file:/Users/charles.strahan/.npmrc
    5 silly config load:file:/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/etc/npmrc
    6 verbose title npm install
    7 verbose argv "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"
    8 verbose logfile logs-max:10 dir:/Users/charles.strahan/.npm/_logs/2025-07-17T23_06_46_036Z-
    9 verbose logfile /Users/charles.strahan/.npm/_logs/2025-07-17T23_06_46_036Z-debug-0.log
    10 warn using --force Recommended protections disabled.
    11 silly packumentCache heap:4496293888 maxSize:1124073472 maxEntrySize:562036736
    12 silly logfile start cleaning logs, removing 1 files
    13 silly logfile done cleaning log files
    14 silly idealTree buildDeps
    15 silly placeDep ROOT backtrace-morgue@1.24.11 OK for:  want: file:../../../../../../../.npm/_cacache/tmp/git-clone8uOUgo
    16 silly reify mark retired [
    16 silly reify   '/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/backtrace-morgue'
    16 silly reify ]
    17 silly reify moves {
    17 silly reify   '/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/backtrace-morgue': '/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/.backtrace-morgue-GKI5Mhaj'
    17 silly reify }
    18 info run backtrace-morgue@1.24.11 prepare ../../../../../../../.npm/_cacache/tmp/git-clone8uOUgo tsc && npm run copy-assets
    19 info run backtrace-morgue@1.24.11 prepare { code: 127, signal: null }
    20 verbose stack Error: command failed
    20 verbose stack     at promiseSpawn (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:22:22)
    20 verbose stack     at spawnWithShell (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:124:10)
    20 verbose stack     at promiseSpawn (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:12:12)
    20 verbose stack     at runScriptPkg (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:79:13)
    20 verbose stack     at runScript (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script.js:9:12)
    20 verbose stack     at /Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/rebuild.js:331:17
    20 verbose stack     at run (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/promise-call-limit/dist/commonjs/index.js:67:22)
    20 verbose stack     at /Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/promise-call-limit/dist/commonjs/index.js:84:9
    20 verbose stack     at new Promise (<anonymous>)
    20 verbose stack     at callLimit (/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/node_modules/promise-call-limit/dist/commonjs/index.js:35:69)
    21 verbose pkgid backtrace-morgue@1.24.11
    22 error code 127
    23 error path /Users/charles.strahan/.npm/_cacache/tmp/git-clone8uOUgo
    24 error command failed
    25 error command sh -c tsc && npm run copy-assets
    26 silly unfinished npm timer reify 1752793606195
    27 silly unfinished npm timer reify:build 1752793606230
    28 silly unfinished npm timer build 1752793606230
    29 silly unfinished npm timer build:links 1752793606231
    30 silly unfinished npm timer build:run:prepare 1752793606231
    31 silly unfinished npm timer build:run:prepare:../../../../../../../.npm/_cacache/tmp/git-clone8uOUgo 1752793606231
    32 verbose cwd /Users/charles.strahan/.npm/_cacache/tmp/git-clone8uOUgo
    33 verbose os Darwin 24.1.0
    34 verbose node v24.4.0
    35 verbose npm  v11.4.2
    36 verbose exit 127
    37 verbose code 127
    38 error A complete log of this run can be found in: /Users/charles.strahan/.npm/_logs/2025-07-17T23_06_46_036Z-debug-0.log
    
  2. cstrahan commented on Jul 17, 2025

    @cstrahan
    Author

    For comparison, here are the logs from when I didn't pass -g:

    0 verbose cli /Users/charles.strahan/.local/share/mise/installs/node/24.4.0/bin/node /Users/charles.strahan/.local/share/mise/installs/node/24.4.0/bin/npm
    1 info using npm@11.4.2
    2 info using node@v24.4.0
    3 timing npm:load:whichnode Completed in 0ms
    4 silly config load:file:/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/lib/node_modules/npm/npmrc
    5 silly config load:file:/Users/charles.strahan/.npm/_cacache/tmp/git-cloneGJMxAH/.npmrc
    6 silly config load:file:/Users/charles.strahan/.npmrc
    7 silly config load:file:/Users/charles.strahan/.local/share/mise/installs/node/24.4.0/etc/npmrc
    8 timing npm:load:configload Completed in 4ms
    9 timing config:load:flatten Completed in 1ms
    10 timing npm:load:mkdirpcache Completed in 0ms
    11 timing npm:load:mkdirplogs Completed in 0ms
    12 verbose title npm run copy-assets
    13 verbose argv "run" "copy-assets"
    14 timing npm:load:setTitle Completed in 7ms
    15 verbose logfile logs-max:10 dir:/Users/charles.strahan/.npm/_logs/2025-07-17T23_12_54_263Z-
    16 verbose logfile /Users/charles.strahan/.npm/_logs/2025-07-17T23_12_54_263Z-debug-0.log
    17 timing npm:load Completed in 24ms
    18 silly logfile start cleaning logs, removing 1 files
    19 silly logfile done cleaning log files
    20 timing command:run Completed in 199ms
    21 timing npm Completed in 244ms
    22 info timing Timing info written to: /Users/charles.strahan/.npm/_logs/2025-07-17T23_12_54_263Z-timing.json
    23 verbose cwd /Users/charles.strahan/.npm/_cacache/tmp/git-cloneGJMxAH
    24 verbose os Darwin 24.1.0
    25 verbose node v24.4.0
    26 verbose npm  v11.4.2
    27 verbose exit 0
    28 info ok
    
  3. added
    Priority 2secondary priority issue
    and removed
    Needs Triageneeds review for next steps
    on Jul 29, 2025
  4. MacOS commented on Jul 24, 2026

    @MacOS

    This BUG is persisting, am I correct? I ask because I have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions