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

166
Vistas
Yarn 2 workspaces not installing dependencies

I'm testing out setting up yarn 2 workspaces. I think I've done it the way I'm supposed to, but when I run yarn install from the root it doesn't install any modules nor does it create the symplink to dependencies as expected. I have the following folder structure

root/
  package-a/
  package-b/

Each contains a package.json and each of the package folders contains an index.js. Here are the package.json files

root:

{
  "name": "yarn-workspaces-poc",
  "version": "1.0.0",
  "license": "MIT",
  "private": true,
  "workspaces": [
    "package-a/",
    "package-b/"
  ]
}

package-a:

{
  "name": "package-a",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "cross-env": "5.0.5",
    "package-b": "workspace:*"
  }
}

package-b:

{
  "name": "package-b",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "dependencies": {
    "cross-env": "5.0.5"
  }
}

Here are the js files

package-a/index.js

import test from "package-b";
console.log('testing');
console.log(test());

package-b/index.js

export default function b() {
  console.log("From b. You made it!");
}

The expected behavior is that when I run yarn install from the root a node_modules folder will be created there. It should contain the cross-env package as well as a folder symlinked to package-b. However nothing gets created. Here's the output from the command:

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 0s 96ms

edit:

Additionally if I just run package-a to test it this is the result:

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'package-b' imported from /root/package-a/index.js
Did you mean to import package-b/index.js?
    at packageResolve (internal/modules/esm/resolve.js:655:9)
    at moduleResolve (internal/modules/esm/resolve.js:696:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:86:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)
    at link (internal/modules/esm/module_job.js:55:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I had a similar problem. It turns out the new version of Yarn does not use node_modules:

https://yarnpkg.com/getting-started/migration#switching-to-plugnplay

https://yarnpkg.com/getting-started/migration#final-notes

This is really confusing as it is at odds with the documentation for workspaces.. which describes the outcome you (and I) were expecting: https://yarnpkg.com/features/workspaces

Once you have run 'yarn install', you can start the servers however you did before but prepending 'yarn workspace WORKSPACENAME '..

so if you would normally start like this:

rootfolder$ cd package-b
package-b$ node index.js

you would now run this from the root folder:

rootfolder$ yarn workspace package-b node index.js

There are a few other things that you may need to setup for your IDE etc.. there is plenty of info here: https://yarnpkg.com/getting-started/migration#switching-to-plugnplay

over 4 years ago · Santiago Trujillo Denunciar

0

Create a .yarnrc.yml at the root of your monorepo,

Add the following property to it:

nodeLinker: node-modules

Perhaps the most notable change with Yarn 2 - is the PnP system. Say goodbye to node_modules

This is the default behaviour unless you specify the "legacy" node-modules linker

Documented here

Bonus info

For deploying packages separately its sometimes useful to prevent hoisting of node_modules to the root.

You can add

nmHoistingLimits: workspaces

To the .yarnc.yml to ensure every package has their dependencies installed directly at the package level.

This is much more robust than the old noHoist: [*/**] from yarn 1.

over 4 years ago · Santiago Trujillo Denunciar
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