npm / npm/cli

[BUG] npx silently fails to install git dependencies with preinstall scripts

Open
#4,137 1 comment 0 reactions 1 assignee View on GitHub

@wraithgar is already working on this.

Since Aug 2, 2022.

cmd:exec Needs Triage Priority 2 Release 8.x
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 exists in the latest npm version
  • I am using the latest npm
Current Behavior

Running

npx <git repo url>

on a repository with a package with a preinstall script defined will fail to install, regardless of how simple the preinstall script is. Nothing will be logged to stdout (including nothing from the preinstall script) and the exit code will be 1.

Expected Behavior

I'd expect running

npx <git repo url>

on a repository with a package with a preinstall script defined would first run the package's preinstall script and then the package's bin.

Steps To Reproduce
  1. Run npx github:ivomurrell/npx-preinstall-bug-test and observe the failed exit code. The behaviour will be the same regardless of whether you accept the CLI prompt, or pass --yes. Likewise if you manually specify the commit, i.e., npx github:ivomurrell/npx-preinstall-bug-test#main. npx-preinstall-bug-test is a skeleton repository with a preinstall script of echo hello.
  2. Run npx github:ivomurrell/npx-preinstall-bug-test#no-preinstall and observe that the bin now executes. The only difference between main and the no-preinstall branch is that the preinstall script is deleted in the latter.
  3. Run npm exec github:ivomurrell/npx-preinstall-bug-test and observe that both the preinstall script and the bin now run. It appears npm exec does not exhibit the same behaviour as npx in this case.
  4. Re-run the original npx github:ivomurrell/npx-preinstall-bug-test command and observe that the bin now runs, but not the preinstall script. This is because the package was successfully installed by the npm exec command and npx can pull it from the cache. The original behaviour from (1) can be observed by using an empty cache, i.e., npx --cache=/tmp/empty-cache github:ivomurrell/npx-preinstall-bug-test.
Environment
  • npm: 8.2.0
  • Node: 16.13.1
  • OS: macOS 11.6
  • platform: Intel Macbook Pro
  • npm config:
; "user" config from /Users/ivo.murrell/.npmrc

fund = false
update-notifier = false

; node bin location = /Users/ivo.murrell/.volta/tools/image/node/16.13.1/bin/node
; cwd = /Users/ivo.murrell/Documents/test/npx-git-preinstall/consuming-package
; HOME = /Users/ivo.murrell
; 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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.