cli
cli copied to clipboard
[BUG] npx silently fails to install git dependencies with preinstall scripts
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
- Run
npx github:ivomurrell/npx-preinstall-bug-testand 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-testis a skeleton repository with apreinstallscript ofecho hello. - Run
npx github:ivomurrell/npx-preinstall-bug-test#no-preinstalland observe that thebinnow executes. The only difference betweenmainand theno-preinstallbranch is that thepreinstallscript is deleted in the latter. - Run
npm exec github:ivomurrell/npx-preinstall-bug-testand observe that both thepreinstallscript and thebinnow run. It appearsnpm execdoes not exhibit the same behaviour asnpxin this case. - Re-run the original
npx github:ivomurrell/npx-preinstall-bug-testcommand and observe that thebinnow runs, but not thepreinstallscript. This is because the package was successfully installed by thenpm execcommand andnpxcan 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.
On further reflection this behaviour seems very similar to what is described in #4003.