/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
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.0Output · 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):
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.jsonOutput
{"name":"root","version":"1.0.0","private":true,"dependencies":{"is-number":"7.0.0"}}Or add it to one workspace package:
pnpm add zod --filter @acme/api # by package name
cd packages/api && pnpm add zod # from inside the package| Goal | Command |
|---|---|
| Dependency of one package | pnpm add PKG --filter NAME |
| Dev tool shared by the whole repo | pnpm add -D PKG -w |
| Same package in every workspace | pnpm add PKG -r (every workspace package) |
| Never see the check again | ignore-workspace-root-check=true in .npmrc |
Sources
Related pages
commands · pnpmpnpm --filter: run a script in one workspace packagepnpm --filter PKG run build runs a script only in the matching workspace packages. Add ... to include dependencies, use globs, directories or "[origin/main]".errors · pnpmERR_PNPM_NO_PKG_MANIFEST No package.json found in ...pnpm install fails with ERR_PNPM_NO_PKG_MANIFEST when the current directory has no package.json. Run it from the project folder or create one with pnpm init.errors · pnpmERR_PNPM_OUTDATED_LOCKFILE Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to dateERR_PNPM_OUTDATED_LOCKFILE means package.json changed but pnpm-lock.yaml was not regenerated, and CI installs with frozen-lockfile. Run pnpm install and commit.