cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] Workspace packages are installed with `--workspaces=false` if root package has no dependencies

Open sgerace opened this issue 2 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

When installing with npm install --workspaces=false, if the root package has no dependencies (neither dependencies nor devDependencies then the --workspaces=false is ignored and the workspace packages are installed.

Please note that I encountered this behavior while developing a reproducible example for #6690, so they may be related, but this seemed like a distinct issue so I decided to report separately (please feel free to close if it turns out to be related to the same root cause).

Expected Behavior

I would expect the --workspaces=false flag to ignore all workspaces and install ONLY dependencies and devDependencies provided in the root package.json.

Steps To Reproduce

  1. Create the following project containing a package.json at the project root and one workspace:

Project structure:

.
+-- package.json
`-- workspace-a
    `-- package.json

./package.json contents:

{
    "name": "npm-workspace",
    "dependencies": {},
    "devDependencies": {},
    "workspaces": [
        "workspace-a"
    ]
}

./workspace-a/package.json contents:

{
    "name": "npm-workspace-a",
    "dependencies": {
        "express": "4.18.1"
    }
}
  1. Run the following command: npm install --workspaces=false

In this case, I would not expect any modules to be installed since workspaces should be ignored and there are no dependencies listed in the root project.json file. However, when I run this command, express and its dependencies are installed.

  1. To demonstrate correct behavior, if you alter the root package.json to include a package:

./package.json contents:

{
    "name": "npm-workspace",
    "dependencies": {
        "inherits": "2.0.4"
    },
    "devDependencies": {},
    "workspaces": [
        "workspace-a"
    ]
}

Running npm install --workspaces=false will now only install the inherits package (and express will not be installed).

Environment

  • npm: 9.8.1
  • Node.js: v18.16.0
  • OS Name: macOS
  • System Model Name: Macbook Pro

sgerace avatar Aug 02 '23 20:08 sgerace

Hello, I'm having the same issue using npm 8.0.0. Is there any progress on the topic? Is there any suggested workaround this?

simonadenic avatar Oct 29 '23 13:10 simonadenic

This could be similer to https://github.com/npm/cli/issues/6690, keeping it open for now. If the identified root cause is the same for the other then, We'll close it as duplicate.

milaninfy avatar May 23 '24 17:05 milaninfy