How to fix npm ERR! code ENOWORKSPACES npm ERR! No workspaces found in npm
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.
Quick fix
Fixes npm ERR! code ENOWORKSPACES npm ERR! No workspaces found
{
"name": "my-monorepo",
"private": true,
"workspaces": [
"packages/*"
]
}- Add workspaces configuration
- Run commands from the root directory
- Check for global workspaces setting
- Use --no-workspaces for unsupported commands
{"name": "my-monorepo","private": true,"workspaces": ["packages/*"]}npm ERR! code ENOWORKSPACESnpm ERR! No workspaces found
What this error means
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.
Typical symptoms
- npm commands fail with 'No workspaces found'
- Error code ENOWORKSPACES
- Workspace commands like 'npm run -ws' fail
- Works in some directories but not others
Common causes
- Missing 'workspaces' field in root package.json
- Running npm from subdirectory instead of monorepo root
- Global workspaces=true in .npmrc affecting non-workspace projects
- Using workspace flags with commands that don't support them
- npm version < 7 which doesn't support workspaces
How to fix "npm ERR! code ENOWORKSPACES npm ERR! No workspaces found"
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@latestAdvanced notes
npm 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.
Frequently asked questions
- What does "npm ERR! code ENOWORKSPACES npm ERR! No workspaces found" mean?
- The ENOWORKSPACES error means npm is looking for workspace configuration but can't find any. json.
- How do I fix "npm ERR! code ENOWORKSPACES npm ERR! No workspaces found"?
- 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.
- What causes "npm ERR! code ENOWORKSPACES npm ERR! No workspaces found"?
- Missing 'workspaces' field in root package.json Running npm from subdirectory instead of monorepo root Global workspaces=true in .npmrc affecting non-workspace projects
- Is the "npm ERR! code ENOWORKSPACES npm ERR! No workspaces found" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 📖npm Docs: Workspaces(Official Docs)
- 🐙GitHub: npm ENOWORKSPACES error(GitHub)
- 💬Stack Overflow: npm workspace errors(Stack Overflow)