This error occurs when npm expects workspaces but none are configured. Usually caused by running workspace commands without a workspaces field in package.json, or running from the wrong directory.
Fixes npm ERR! code ENOWORKSPACES npm ERR! No workspaces found
{
"name": "my-monorepo",
"private": true,
"workspaces": [
"packages/*"
]
}{"name": "my-monorepo","private": true,"workspaces": ["packages/*"]}npm ERR! code ENOWORKSPACESnpm ERR! No workspaces found
The ENOWORKSPACES error means npm is looking for workspace configuration but can't find any. This happens when: - You're running a workspace-aware command but your package.json doesn't have a `workspaces` field - You're running npm from a subdirectory instead of the monorepo root - You have `workspaces=true` set globally in .npmrc but the project isn't a workspace - Using npm commands that don't support workspaces (like certain `npm config` operations in npm 9.3+) npm workspaces require npm 7+ and a properly configured root package.json.
If you're setting up a monorepo, add the workspaces field to your root package.json:
{
"name": "my-monorepo",
"private": true,
"workspaces": [
"packages/*"
]
}Common patterns:
- "packages/*" - all directories in packages/
- "apps/*" - all directories in apps/
- ["packages/*", "apps/*"] - multiple directories
Workspace commands must run from the monorepo root:
# Wrong: running from subdirectory
cd packages/my-package
npm run build # May fail with ENOWORKSPACES
# Correct: run from root with workspace flag
cd /path/to/monorepo-root
npm run build --workspace=my-package
# or
npm run build -w my-packageYou might have workspaces enabled globally in .npmrc:
# Check your .npmrc
cat ~/.npmrc
# If you see workspaces=true, remove it
npm config delete workspaces --location=userThis setting forces all projects to be treated as workspaces.
Some npm commands don't support workspaces. Use the flag to skip workspace processing:
npm config list --no-workspaces
npm config get registry --no-workspacesWorkspaces require npm 7 or later:
npm --version
# If below 7, upgrade npm
npm install -g npm@latestnpm 9.3+ breaking change: Starting with npm 9.3.0, some commands that don't support workspaces throw ENOWORKSPACES instead of silently ignoring the flag. Use --no-workspaces explicitly.
Workspace initialization: Create a new workspace package properly:
npm init -w ./packages/new-packageThis creates the directory and updates the root package.json automatically.
Next.js/Turborepo gotcha: Some frameworks have their own workspace detection that can conflict with npm. If using Turborepo, ensure you're running commands through turbo not directly with npm.
Lerna migration: If migrating from Lerna to npm workspaces, ensure you've added the workspaces field—Lerna used lerna.json which npm doesn't read.