Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 565
Red Baron Avatar asked Mar 19 '20 08:03

Red Baron


People also ask

What does yarn look for in a package JSON file?

Every yarn package must have a package.json file which yarn looks for in order to identify the package. This file configures the behavior of yarn while it is running inside that package.

How do I configure yarn to run a specific package?

Configuring your package Every yarn package must have a package.json file which yarn looks for in order to identify the package. This file configures the behavior of yarn while it is running inside that package. Let us consider a project named scam-register, this package will have a package.json file located at scam-register/package.json:

What is the package JSON file for?

The package.json file is kind of a manifest for your project. It can do a lot of things, completely unrelated. It's a central repository of configuration for tools, for example. It's also where npm and yarn store the names and versions for all the installed packages. It's empty!

Can I use yarn instead of NPM install to install dependencies?

The equivalent of $ npm install is just $ yarn (without arguments) to install all dependencies from package.json. Just found that it has only package.json, which means I can only use npm install to install dependencies. Would there be no problem when I use yarn later? Doesn't matter whether you use yarn or npm, there will always be a package.json.


1 Answers

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.

like image 177
Mike McG Avatar answered Sep 28 '22 01:09

Mike McG