npm/pnpm/yarn
Workspaces Commands
Manage multiple packages in a single repository with npm workspaces. Share dependencies, link local packages, and run commands across your entire monorepo.
9 commands
Pro Tips
Run a script in a specific workspace: 'npm run build -w packages/shared' — the -w flag targets one package.
Install a dependency in a workspace: 'npm install lodash -w packages/api' — keeps it scoped to that package.
Run across all workspaces: 'npm run test --workspaces' runs the test script in every workspace.
Common Mistakes
Workspace hoisting means packages can accidentally import undeclared dependencies. Each package.json must list its own deps.
npm workspaces require npm 7+. Older npm versions silently ignore the 'workspaces' field in package.json.