cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open ivomurrell opened this issue 4 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] 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.

ivomurrell avatar Dec 07 '21 20:12 ivomurrell

On further reflection this behaviour seems very similar to what is described in #4003.

ivomurrell avatar Dec 08 '21 10:12 ivomurrell