Skip to content

[BUG] Global installation / reinstallation of git packages fails if certain npm scripts are present #6984

@paulbrimicombe

Description

@paulbrimicombe

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.

  1. If any of the following scripts are present, the global installation fails with an ENOENT error:

    • install
    • preinstall
    • postinstall
  2. 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
  3. 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)

  1. Create an NPM package in git (e.g. https://github.com/paulbrimicombe/npm-git-package) with an install / preinstall / postinstall script

  2. 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
  3. 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)

  1. Create an NPM package in git (e.g. https://github.com/paulbrimicombe/npm-git-package) with a build / prepack / prepare script

  2. 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
  3. 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)

  1. Create an NPM package in git (e.g. https://github.com/paulbrimicombe/npm-git-package) with a build / prepack / prepare script

  2. 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
  3. 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
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueRelease 9.xwork is associated with a specific npm 9 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions