yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.44k stars 2.73k forks source link

Running yarn add inside a workspace with pnp enabled installs all node_modules #6614

Open onigoetz opened 6 years ago

onigoetz commented 6 years ago

Do you want to request a feature or report a bug? Bug

What is the current behavior? I have a project with a workspace (around 10 packages) When I run yarn add inside one of the workspaces, it installs all node_modules even though I enabled PNP on the root package

If the current behavior is a bug, please provide the steps to reproduce.

  1. Have a project with workspaces
  2. Run yarn --pnp on the root
  3. Go to one of the packages
  4. Run yarn add -D jest-pnp-resolver jest-resolve
  5. You can see that all node_modules have been reinstalled

What is the expected behavior?

Step 5 should be that it installed the package, but no node_modules should be present

Please mention your node.js, yarn and operating system version.

MacOS 10.14 Node 10.13.0 Yarn 1.12.1

ericclemmons commented 6 years ago

It also happens via yarn workspace NAME add [...deps].

KwanMan commented 6 years ago

seems the workspace package.json also needs

{
  "installConfig": {
    "pnp": true
  }
}

which i assume is a bug, i assume it's supposed to inherit from the root package.json

onigoetz commented 6 years ago

@KwanMan I do have this on the workspace root, it was added when I ran yarn --pnp for the first time. Should I have it on all the sub-packages as well ?

KwanMan commented 6 years ago

Yea I had to add it to any sub-package I wanted to run yarn add in. Then it installed as expected, no node_modules

onigoetz commented 6 years ago

Good to know there is a workaround, but I'd expect that it understand that it's in a pnp-enabled repo, like it can understand when it's in a workspace and install the dependencies in the parent.

arendjr commented 4 years ago

I stumbled upon this bug because I was searching whether it's possible to have a monorepo with PnP enabled in some of the workspaces, but not in others. Seems that thanks to this "bug" it is? In that case for me it's a feature, though I admit it might be a confusing one.

In any case, I thought I'd mention this, because if this gets fixed, it would be nice if there's an official way to enable PnP is some workspaces only.