How to fix npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple workspaces with the same name in npm
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.
Quick fix
Fixes npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple workspaces with the same name
find . -path ./node_modules -prune -o -name 'package.json' -type f -exec grep -H '"name"' {} \;- Find all duplicate workspace package names
- Examine your root package.json workspaces configuration
- Rename duplicate workspace packages
- Clear npm cache and reinstall dependencies
find . -path ./node_modules -prune -o -name 'package.json' -type f -exec grep -H '"name"' {} \;npm ERR! code EDUPLICATEWORKSPACEnpm ERR! must not have multiple workspaces with the same name
What this error means
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.
Typical symptoms
- npm install fails with the error message 'must not have multiple workspaces with the same name'
- The error provides no details about which packages have duplicate names
- Monorepo operations like npm run scripts across workspaces fail to execute
- Workspace dependency resolution fails when trying to reference dependencies across packages
- CI/CD pipelines fail during the install phase with unclear error messaging
Common causes
- Two or more packages in your workspaces have identical `name` values in their package.json files
- Accidentally copy-pasting a package folder without updating the name field in package.json
- Merging code from different branches that each created similarly-named packages
- Auto-generated or templated packages that retained placeholder names across multiple workspaces
- Scoped packages with identical base names in different workspaces
How to fix "npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple workspaces with the same name"
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.
Advanced notes
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.
Frequently asked questions
- What does "npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple work" mean?
- 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. json name field, not by their folder names, so duplicates cause ambiguity in the dependency resolution and workspace management system.
- How do I fix "npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple work"?
- 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.
- What causes "npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple work"?
- Two or more packages in your workspaces have identical name values in their package.json files Accidentally copy-pasting a package folder without updating the name field in package.json Merging code from different branches that each created similarly-named packages
- Is the "npm ERR! code EDUPLICATEWORKSPACE npm ERR! must not have multiple work" 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
- ๐npm Official Documentation
- ๐Docs: npm workspaces(Official Docs)
- ๐ฌSO: npm workspace issues(Stack Overflow)
- ๐GitHub: npm repository(GitHub)