Skip to content

[BUG] workspaces infinite loop when running child scripts #5722

Closed
@ianstormtaylor

Description

@ianstormtaylor

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

With workspaces, if you try to run all child scripts of name via a root script of the same name that uses the dotenv CLI, it will go into an infinite loop.

For example, in root:

{
  "name": "infinte-loop-example",
  "version": "0.0.0",
  "workspaces": ["a", "b"]
  "scripts": {
    "build": "dotenv npm run build --workspaces"
  }
}

And assuming a and b both define their own build scripts... If you run npm run build, you'll get an infinite loop:

$ npm run build

> infinte-loop-example@0.0.0 build
> dotenv npm run build --workspaces

> infinte-loop-example@0.0.0 build
> dotenv npm run build --workspaces

> infinte-loop-example@0.0.0 build
> dotenv npm run build --workspaces

> infinte-loop-example@0.0.0 build
> dotenv npm run build --workspaces

Expected Behavior

No infinite loop, and the a and b workspace build script is run.

Steps To Reproduce

See above.

Environment

  • npm: 8.19.2
  • Node.js: 18.11.0
  • OS Name: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions