This error occurs when npm cannot find a workspace with the name you specified using the --workspace flag. It typically happens due to package name mismatches between package.json and folder structure.
The EUNKNOWNWORKSPACE error occurs in npm monorepo projects when you attempt to run commands with the --workspace (-w) flag, but npm cannot locate a workspace matching that name. npm identifies workspaces by the 'name' field in each workspace's package.json file, not by the folder name. If the workspace name you specified doesn't match any configured workspace's package name, npm raises this error. This is a common confusion point because developers often expect workspaces to be identified by their directory names rather than their package.json names.
Open your project's root package.json and check the 'workspaces' field to confirm it includes the directory pattern containing your workspace.
{
"name": "my-monorepo",
"workspaces": [
"packages/*"
]
}Make sure the glob pattern matches your actual folder structure.
Open the package.json file inside the workspace directory and verify the 'name' field. This is the identifier npm uses.
{
"name": "@myapp/frontend",
"version": "1.0.0"
}If the workspace folder is 'packages/frontend', but the name is '@myapp/frontend', you must use '@myapp/frontend' when referencing it in npm commands.
Replace your command with the correct workspace package name. Use the 'name' field from the workspace's package.json, not the folder name.
# Incorrect - uses folder name
npm run build -w frontend
# Correct - uses package name from package.json
npm run build -w @myapp/frontendYou can also run commands in all workspaces by omitting the -w flag entirely: npm run build
Run npm with the --workspaces flag to see all configured workspaces and their actual package names:
npm run --workspaces
# Or use npm list to see all workspaces:
npm list --workspacesThis will show you the exact package names npm recognizes for your workspaces.
If you've recently changed workspace configuration or package names, clear npm's cache and reinstall dependencies:
npm cache clean --force
rm package-lock.json
npm installThis ensures npm's internal workspace registry is updated with the correct workspace names.
When upgrading to npm 7+, some developers encounter workspace issues due to breaking changes in workspace handling. If you're migrating from npm 6 or earlier, ensure all workspace packages have unique names and are properly referenced. Additionally, be aware that some npm commands don't support workspaces and require the --no-workspaces flag. If you're using the 'workspace:' protocol (common in pnpm), you'll need to use pnpm instead of npm, or replace 'workspace:*' dependencies with specific version numbers.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error