Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
Yarn add creates yarn.lock and node_modules folder inside sub-package in yarn workspace

I am using a yarn workspace, and wonder why yarn creates a yarn.lock and a node_modules folder in the sub-projects when adding dependencies via yarn add ....

As an example, imagine the following simple yarn workspace:

{
  "private": true,
  "workspaces: [
    "./packages/*"
  ]
}

File structure with sub-project named "subpackage".

enter image description here

Then I add a dependency to the "subpackage" using the following command:

yarn workspace subpackage add lodash

After that, the file folders change as follows:

enter image description here

I wonder why yarn creates the yarn.lock and the node_modules folder when I am in a workspace and even explicitly use the workspace version of the add command. Shouldn't all dependencies be managed through the root workspace directory?

I didn't really find a clear answer to this in the yarn documentation, however this blog-post, which introduced the workspace feature, clearly confirms the expected behaviour:

If you want to modify a dependency of a Workspace, just run the appropriate command inside the Workspace folder:

$ cd packages/jest-matcher-utils/
$ yarn add left-pad
✨ Done in 1.77s.
$ git status
modified: package.json
modified: ../../yarn.lock

Note that Workspaces don’t have their own yarn.lock files, and the root yarn.lock contains all the dependencies for all the Workspaces. When you want to change a dependency inside a Workspace, the root yarn.lock will be changed as well as the Workspace’s package.json.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda