This error occurs when you run an npm workspace command with a filter that doesn't match any workspace in your monorepo. It typically happens due to package name mismatches between what you specify with --workspace and what's configured in package.json files.
Fixes ENOWORKSPACES
{
"name": "@mycompany/my-package",
"version": "1.0.0"
}{"name": "@mycompany/my-package","version": "1.0.0"}npm ERR! code ENOWORKSPACESnpm ERR! No workspaces matched the filter
The ENOWORKSPACES error indicates that npm couldn't find any workspace packages matching your filter criteria. This typically occurs when you specify a workspace name with --workspace that doesn't match the name field in any package.json, or when you're running a command that doesn't support workspaces.
Check the exact package names configured in your monorepo. Look at the 'name' field in each workspace's package.json:
{
"name": "@mycompany/my-package",
"version": "1.0.0"
}Note the full package name including any @scope prefix.
Use the exact package name from package.json, not the folder name:
# WRONG - using folder name
npm run build --workspace=my-package
# CORRECT - using the name field
npm run build --workspace=@mycompany/my-packageCheck what workspaces npm recognizes:
cat package.json | grep -A 5 '"workspaces"'Then check each workspace's package.json name field.
You can use --workspace with a directory path:
# Target a specific directory
npm run build --workspace packages/app
# Run in ALL workspaces
npm run build --workspacesNote: Use --workspaces (plural) to run in all workspaces.
Some npm commands don't support workspaces. Use --no-workspaces:
npm config list --no-workspacesIf not all workspaces have the same npm script, use --if-present:
npm run test --workspaces --if-presentThis skips workspaces without the target script.
The ENOWORKSPACES error is fundamentally a filter matching issue. npm uses exact string matching on the 'name' field from package.json files—it does not support glob patterns or fuzzy matching. When you use --workspace, npm reads your root package.json workspaces array to find workspace directories, then reads each workspace's package.json to get its name. Your filter must match one of those names exactly.