[BUG] Global installation / reinstallation of git packages fails if certain npm scripts are present
Nobody has claimed this yet.
- 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
There appear to be various issues with global installation of packages from git that have build / install / preinstall / postinstall / prepack / prepare scripts. Local installation appears to work as expected.
-
If any of the following scripts are present, the global installation fails with an
ENOENTerror:installpreinstallpostinstall
-
If any of the following scripts are present, the first global installation results in the package being symlinked to the NPM cache directory which is ephemeral:
buildprepackprepare
-
If any of the following scripts are present, a global reinstallation fails with an
ENOTDIRerror:buildprepackprepare
I've tried various combinations of --install-links and --ignore-scripts but neither fixes these issues (--install-links changes the error code for the reinstallation bug to ENOTEMPTY). I've raised a single Issue for all of these bugs because they seem to be related.
Expected Behavior
Global installation of git packages should work in the same way as local installation:
- Installation should not fail regardless of which scripts are present in the package
- Reinstallation should not fail regardless of which scripts are present in the package
- The installed package directory should not be a symlink to the NPM cache
Steps To Reproduce
First bug (first installation failure)
-
Create an NPM package in git (e.g. https://github.com/paulbrimicombe/npm-git-package) with an
install/preinstall/postinstallscript -
Verify that local installation works correctly:
# All of these should run successfully and the code will have been copied to node_modules/npm-git-package npm install paulbrimicombe/npm-git-package#with-install-script npm install paulbrimicombe/npm-git-package#with-preinstall-script npm install paulbrimicombe/npm-git-package#with-postinstall-script -
Attempt global installation - all of these will fail with
ENOENTfor the target global installation path for the package, i.e.{GLOBAL_NPM_PATH}/lib/node_modules/npm-git-package:npm install --global paulbrimicombe/npm-git-package#with-install-script npm install --global paulbrimicombe/npm-git-package#with-preinstall-script npm install --global paulbrimicombe/npm-git-package#with-postinstall-script
Second bug (installation is symlinked to NPM cache)
-
Create an NPM package in git (e.g. https://github.com/paulbrimicombe/npm-git-package) with a
build/prepack/preparescript -
Verify that local installation works correctly:
# All of these should run successfully and the code will have been copied to node_modules/npm-git-package npm install paulbrimicombe/npm-git-package#with-build-script npm install paulbrimicombe/npm-git-package#with-prepack-script npm install paulbrimicombe/npm-git-package#with-prepare-script -
Install globally - all of these will complete successfully but
{GLOBAL_NPM_PATH}/lib/node_modules/npm-git-packagewill be a symlink to the ephemeral NPM cache:npm install --global paulbrimicombe/npm-git-package#with-build-script npm install --global paulbrimicombe/npm-git-package#with-prepack-script npm install --global paulbrimicombe/npm-git-package#with-prepare-script
Third bug (cannot globally reinstall packages with certain scripts)
-
Create an NPM package in git (e.g. https://github.com/paulbrimicombe/npm-git-package) with a
build/prepack/preparescript -
Verify that local installation works correctly:
# All of these should run successfully and the code will have been copied to node_modules/npm-git-package npm install paulbrimicombe/npm-git-package#with-build-script npm install paulbrimicombe/npm-git-package#with-prepack-script npm install paulbrimicombe/npm-git-package#with-prepare-script -
Install globally once (these will all pass):
npm install --global paulbrimicombe/npm-git-package#with-build-script npm install --global paulbrimicombe/npm-git-package#with-prepack-script npm install --global paulbrimicombe/npm-git-package#with-prepare-script -
Attempt reinstallation — these will all fail with an
ENOTDIRerror:npm install --global paulbrimicombe/npm-git-package#with-build-script npm install --global paulbrimicombe/npm-git-package#with-prepack-script npm install --global paulbrimicombe/npm-git-package#with-prepare-script
Environment
- npm: 9.9.1 (also tested on 8.x and had the same issue)
- Node.js: 18.18.2 (also tested on 16 and had the same issue)
- OS Name: Darwin Kernel 23 (MacOS)
- npm config (since this is a global installation problem, I've included
--global):
; "cli" config from command line options
global = true
; node bin location = /Users/XXXXX/.local/share/nvm/v18.18.2/bin/node
; node version = v18.18.2
; npm local prefix = /Users/XXXXX/Development/toys/npm-install-tests
; npm version = 9.9.1
; cwd = /Users/XXXXX/Development/toys/npm-install-tests
; HOME = /Users/XXXXX
; Run `npm config ls -l` to show all defaults.
; copy and paste output from `npm config ls` here
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction commands and the npm-git-package fixture branches named in the issue, comparing local and global installs. Trace the global git-package installation and reinstallation paths, then verify behavior for install, preinstall, postinstall, build, prepack, and prepare scripts. Done means global installation and reinstallation succeed and the installed package is not a symlink to the npm cache.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, javascript, node.js
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100