Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda