Skip to content

/errors/pnpm/err-pnpm-adding-to-root

ERR_PNPM_ADDING_TO_ROOT Running this command will add the dependency to the workspace root

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
pnpm
exit code
1
versions
pnpm 7 – 10
os
any

ERR_PNPM_ADDING_TO_ROOT means pnpm add ran at the root of a pnpm workspace (the folder with pnpm-workspace.yaml). pnpm refuses because dependencies usually belong to a workspace package, not to the root package.json. Use pnpm add PACKAGE --filter NAME to add it to one package, or pnpm add PACKAGE -w if you really want it at the root.

Reproduce it

bash
cat > package.json <<'EOF'
{ "name": "root", "version": "1.0.0", "private": true }
EOF
printf 'packages:\n  - "packages/*"\n' > pnpm-workspace.yaml
npx --yes pnpm@9 add is-number@7.0.0

Output · exit 1

 ERR_PNPM_ADDING_TO_ROOT  Running this command will add the dependency to the workspace root, which might not be what you want - if you really meant it, make it explicit by running this command again with the -w flag (or --workspace-root). If you don't want to see this warning anymore, you may set the ignore-workspace-root-check setting to true.

Fix

Add it to the root on purpose with -w (--workspace-root):

bash
cat > package.json <<'EOF'
{ "name": "root", "version": "1.0.0", "private": true }
EOF
printf 'packages:\n  - "packages/*"\n' > pnpm-workspace.yaml
npx --yes pnpm@9 add -w is-number@7.0.0 >/dev/null
grep -A2 '"dependencies"' package.json

Output

{"name":"root","version":"1.0.0","private":true,"dependencies":{"is-number":"7.0.0"}}

Or add it to one workspace package:

bash
pnpm add zod --filter @acme/api     # by package name
cd packages/api && pnpm add zod     # from inside the package
GoalCommand
Dependency of one packagepnpm add PKG --filter NAME
Dev tool shared by the whole repopnpm add -D PKG -w
Same package in every workspacepnpm add PKG -r (every workspace package)
Never see the check againignore-workspace-root-check=true in .npmrc

Sources