How to add dependency to PNPM workspace?
Asked Answered
M

1

24

I start using PNPM Workspaces, and I'm struggling in how to add dependencies to any specific workspace as I would do in yarn running:

yarn workspace <workspace_name> add <package_to_add>

Or even running scripts for specific packages as I would do in yarn like:

yarn workspace <workspace_name> run <script>

How is the PNPM community doing this? You really need to go to the workspace package.json file and add it manually?

Been a while searching for docs without success

Thanks!

Medical answered 9/2, 2022 at 18:9 Comment(0)
M
37

So I found an answer and is using the --filter option.

i.e.

# Using the exact package name
pnpm add <package_to_add> --filter <workspace_name>
# Or using a pattern
pnpm add <package_to_add> --filter <prefix>/*

Same for run, etc...

Medical answered 10/2, 2022 at 8:26 Comment(2)
Since Version 9 of pnpm I had to use also the --workspace flag like pnpm add <package_to_add> -F <workspace_name> --workspaceTainataint
I tried in my monorepo but failed with No projects matched the filtersDisarrange

© 2022 - 2024 — McMap. All rights reserved.