How to resolve dependencies in PNPM workspace?

2k Views Asked by At

I have a pnpm workspace with the following structure:

root
|- example
|  |- package.json
|
|- packages
|  |- a
|  |  |- package.json
|  |
|  |- b
|  |  |- package.json
|  |  
|  |- c
|  |  |- package.json

The package c is a package that should contain a and b:

{
  "name": "c",
  "dependencies": {
    "a": "workspace:*",
    "b": "workspace:*"
  }
}

package.json file in example looks like this:

{
  "name": "example",
  "dependencies": {
    "c": "workspace:*"
  }
}

When I do pnpm install it places only c dependency in example/node_modules - it does not install necessary packages a and b.

What do I have to do to have all nested dependencies installed correctly?

2

There are 2 best solutions below

0
On

They are installed correctly. The c inside root/example/node_modules is a symlink to root/packages/c. The dependencies of c are symlinked to root/packages/c/node_modules.

0
On

When I do pnpm install it places only c dependency in example/node_modules - it does not install necessary packages a and b.

That's the default and intended behavior of node_modules with pnpm. This article explains it better