Yarn: Running yarn add inside a workspace with pnp enabled installs all node_modules

Created on 1 Nov 2018  路  6Comments  路  Source: yarnpkg/yarn

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

triaged

Most helpful comment

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.

All 6 comments

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

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

@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 ?

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

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.

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.

Was this page helpful?
0 / 5 - 0 ratings