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.
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.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error