Documentation

Pnpm workspace is a powerful tool for managing multiple packages in a single repository. It can help you keep your dependencies in sync and reduce the time and disk space required for package installation. If you're working on a project that uses pnpm workspace, you can take advantage of this feature to manage your packages more efficiently.

Another feature of pnpm workspace is hoisting, which allows you to install dependencies at the root level instead of in each workspace. This can further reduce the disk space and installation time required for your packages.

Overall, pnpm workspace can be a powerful tool for managing multiple packages in a single repository. It can help you keep your dependencies in sync and reduce the time and disk space required for package installation. If you're new to pnpm workspace, it's worth taking the time to learn how to use it effectively.


Useful resources:

Pnpm use a pnpm-workspace.yaml file to define the workspace structure. This file is located at the root of the project and contains a list of workspace directories.

yaml

All folders listed in this file that contains a package.json file will be considered in the workspace. You can use wildcards to automatically include all folders that match a pattern, like with the layers/* entry above.

As an example, you could create a new folder for your backend and add it to the workspace:

yaml

Then create a package.json file in the .backend folder:

json

By default, if you don't specify a package filter, pnpm will install dependencies in the root package.json file. This is not what we want when using pnpm workspace.

Instead we want to install it in the package that contains our layer. For example, if we want to install a dependency in the .app layer, we should use the following command:

bash

This will find packages in the workspace that has the name app in their package.json and install the dependency in it (here it matches <app>/package.json name).

We could use my-backend from the previous example instead of app to install the dependency in the .backend package.

Another option is to run pnpm install in the layer directory. This will install dependencies in the layer directory instead of the root directory.

bash

If you want to update a dependency in a workspace, you should use the update command with the --recursive flag in order to update the dependency in all layers.

bash

Select dependencies you want to update and press enter.

Once the update is done, you need to remove all node_modules folder using pnpm clean:all, delete the pnpm-lock.yaml file and run pnpm install again.

Note that it may be possible that we have patched some dependencies, updating them may or may not include our fixes. If you encounter any issue, please report it on our Support Portal.

Alternatively, you can also use find unix command to find all node_modules directory in the workspace and delete them:

bash

Useful resources: