This error occurs when your npm monorepo has multiple workspace packages with identical names in their package.json files. Each workspace must have a unique name value to avoid conflicts.
In npm workspaces, the `name` field in each package.json serves as the unique identifier for that workspace. When npm detects two or more packages with the same `name` value across your monorepo structure, it cannot determine which workspace to reference and throws the EDUPLICATEWORKSPACE error. Workspaces are identified by their package.json name field, not by their folder names, so duplicates cause ambiguity in the dependency resolution and workspace management system. This is a strict requirement in npm (and Yarn) to ensure workspace integrity.
First, identify which workspaces have duplicate names. You can use grep to extract all workspace names:
find . -path ./node_modules -prune -o -name 'package.json' -type f -exec grep -H '"name"' {} \;On Windows PowerShell:
Get-ChildItem -Path . -Filter 'package.json' -Recurse | Select-String '"name"'This will show all package.json files with their name fields. Look for any names that appear more than once.
Review the workspaces field in your root package.json to understand which directories are included:
{
"name": "my-monorepo",
"workspaces": [
"packages/*",
"apps/*",
"services/*"
]
}Note all glob patterns, as they may be catching duplicate packages.
Update the name field in each duplicate package.json to be unique. Use a consistent naming convention, preferably with scoping:
{
"name": "@mycompany/auth",
"version": "1.0.0"
}For example, if you have packages/api and services/api both with name "api", rename them to:
- packages/api/package.json: "name": "@mycompany/api-packages"
- services/api/package.json: "name": "@mycompany/api-services"
After updating all duplicate package names, clean your npm cache and reinstall:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installThis ensures npm re-validates your workspace configuration with the corrected names.
After renaming, update any cross-workspace dependencies in your package.json files to reference the new names:
{
"name": "@mycompany/app",
"dependencies": {
"@mycompany/api-services": "workspace:*"
}
}The workspace:* protocol ensures the dependency points to the local workspace version rather than npm registry.
Unlike pnpm, which allows multiple projects with the same name in a monorepo, npm strictly enforces unique workspace names due to how it resolves and hoists dependencies. If you're using scoped packages (e.g., @mycompany/package-name), ensure the full scoped name is unique, not just the base package name. The npm error message intentionally doesn't specify which packages are duplicated; use the grep command to identify duplicates before npm install runs.
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