15

I have the classic Lerna set up. root directory, packages folder, 2 subdirectories

I want to just run yarn install inside one package and just to install the dependencies for this package. for some reason when I run it (even from inside this folder) it's then installing node_modules inside the root, packageA and packageB.

is there a solution to just allow me to install node_modules for a chosen directory?

Red Baron
  • 7,181
  • 10
  • 39
  • 86
  • Have you tried `lerna add package --scope=module` https://github.com/lerna/lerna/tree/master/commands/add#examples? – Clarity Mar 19 '20 at 08:56
  • 2
    @Clarity but I want to say add my 20 dependencies into packageA and ignore the other 5 dependencies in packageB. why is it so hard to just install dependencies in one package? – Red Baron Mar 19 '20 at 10:44

2 Answers2

11

Check out 'focused workspaces' https://classic.yarnpkg.com/blog/2018/05/18/focused-workspaces/

From inside the package you want to work on, run

yarn install --focus

and Yarn will install the local dependencies as well as any dependencies in monorepo-sibling dependencies, but not all dependencies across all packages in the monorepo.

Mike McG
  • 356
  • 2
  • 5
  • 5
    At least with Yarn 1 this works only if all dependencies have been pushed to remote registry: https://github.com/yarnpkg/yarn/issues/5864 – h-kippo Sep 20 '21 at 06:48
2

Do the following from the root directory:

yarn workspace <workspace-name> add <package-name>
basickarl
  • 37,187
  • 64
  • 214
  • 335