-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
ENOENT
error:install
preinstall
postinstall
-
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:
build
prepack
prepare
-
If any of the following scripts are present, a global reinstallation fails with an
ENOTDIR
error:build
prepack
prepare
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
/postinstall
script -
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
ENOENT
for 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
/prepare
script -
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-package
will 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
/prepare
script -
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
ENOTDIR
error: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