Red Baron
Red Baron

Reputation: 7642

How to install packages in just one package.json file in Yarn workspaces?

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?

Upvotes: 16

Views: 27981

Answers (2)

basickarl
basickarl

Reputation: 40444

Do the following from the root directory:

yarn workspace <workspace-name> add <package-name>

Upvotes: 8

Mike McG
Mike McG

Reputation: 386

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.

Upvotes: 14

Related Questions