Skip to content

[BUG] "npm rebuild" runs any symlinked package's lifecycle scripts twice. #2905

Description

@DeeDeeG

Current Behavior:

A package dependency installed as a symlink will get its lifecycle scripts (such as postinstall) run twice when running the npm rebuild subcommand of npm.

Expected Behavior:

Lifecycle scripts should probably only be run once.

Steps To Reproduce:

Set up a minimal/dummy dependency with lifecycle scripts:

  • mkdir test && cd test && npm init -y
  • mkdir dependency && cd dependency && npm init -y
  • Add this as a preinstall script for the dependency dummy package: "preinstall": "echo 'You will see this twice!'

Add the dummy package with lifecycle scripts as a symlinked dependency:

  • cd ..
  • npm install ./dependency

Run npm rebuild and verify that the lifecycle script runs twice:

  • npm rebuild --foreground-scripts

Example output:

% npm rebuild --foreground-scripts

> [email protected] preinstall
> echo 'You will see this twice!'

You will see this twice!

> [email protected] preinstall
> echo 'You will see this twice!'

You will see this twice!
rebuilt dependencies successfully

Environment:

  • OS: macOS Catalina 10.15.7
  • Node: v15.12.0
  • npm: 7.6.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingPriority 1high priority issueRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions