How to fix npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-name" in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025ยท 130 views

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.

Quick fix

Fixes npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-name"

{
  "name": "my-monorepo",
  "workspaces": [
    "packages/*"
  ]
}
  1. Verify workspace configuration in root package.json
  2. Check the package.json name field in each workspace
  3. Use the correct workspace name in your commands
  4. List all available workspaces to verify names
npm โ€” error
{
"name": "my-monorepo",
"workspaces": [
"packages/*"
]
}
npm ERR! code EUNKNOWNWORKSPACE
npm ERR! Unknown workspace: "package-name"

What this error means

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.

Typical symptoms

  • Running 'npm run <script> -w <name>' fails with 'Unknown workspace' error
  • Workspace commands work sometimes but not others depending on how you reference the workspace
  • Error message includes the exact package name npm couldn't find in the workspace filter set
  • Commands work at the root but fail when trying to target a specific workspace
  • Confusion between using folder names vs package names when running workspace commands

Common causes

  1. Using the folder name instead of the package name from package.json (most common)
  2. Mismatch between the folder name and the 'name' field in the workspace's package.json
  3. Typos in the workspace name or package name reference
  4. Workspace not listed in the root package.json's 'workspaces' glob patterns
  5. Using scoped package names incorrectly or forgetting the scope prefix

How to fix "npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-name""

1Verify workspace configuration in root package.json

Open your project's root package.json and check the 'workspaces' field to confirm it includes the directory pattern containing your workspace.

json
{
  "name": "my-monorepo",
  "workspaces": [
    "packages/*"
  ]
}

Make sure the glob pattern matches your actual folder structure.

2Check the package.json name field in each workspace

Open the package.json file inside the workspace directory and verify the 'name' field. This is the identifier npm uses.

json
{
  "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.

3Use the correct workspace name in your commands

Replace your command with the correct workspace package name. Use the 'name' field from the workspace's package.json, not the folder name.

bash
# Incorrect - uses folder name
npm run build -w frontend

# Correct - uses package name from package.json
npm run build -w @myapp/frontend

You can also run commands in all workspaces by omitting the -w flag entirely: npm run build

4List all available workspaces to verify names

Run npm with the --workspaces flag to see all configured workspaces and their actual package names:

bash
npm run --workspaces

# Or use npm list to see all workspaces:
npm list --workspaces

This will show you the exact package names npm recognizes for your workspaces.

5Rebuild workspace cache if necessary

If you've recently changed workspace configuration or package names, clear npm's cache and reinstall dependencies:

bash
npm cache clean --force
rm package-lock.json
npm install

This ensures npm's internal workspace registry is updated with the correct workspace names.

Advanced notes

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.

Frequently asked questions

What does "npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-n" mean?
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. 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.
How do I fix "npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-n"?
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.
What causes "npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-n"?
Using the folder name instead of the package name from package.json (most common) Mismatch between the folder name and the 'name' field in the workspace's package.json Typos in the workspace name or package name reference
Is the "npm ERR! code EUNKNOWNWORKSPACE npm ERR! Unknown workspace: "package-n" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading