Resolving 'Workspace extension with invalid name (defaultProject) found' in Angular
Problem
When running ng serve
in an Angular project, encountering the error:Workspace extension with invalid name (defaultProject) found
.
This issue occurs due to a deprecated configuration property in your angular.json
file. Attempts to resolve it via dependency fixes like npm install --legacy-peer-deps
are ineffective since it’s unrelated to package installations.
Solution
Remove the Deprecated defaultProject
Property
Modern Angular CLI versions (≥v6) no longer require the defaultProject
property. Its presence triggers the error. Here’s how to resolve it:
- Open
angular.json
in your project root - Locate the top-level
defaultProject
entry (usually near the file’s beginning) - Delete the line containing
"defaultProject": "your-project-name"
- Save the file and re-run
ng serve
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"defaultProject": "my-app",
"newProjectRoot": "projects",
"projects": {
"my-app": { ... }
}
}
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-app": { ... }
}
}
What If You Have Multiple Projects?
If your workspace contains multiple projects:
- Remove
defaultProject
fromangular.json
(it’s deprecated regardless) - Explicitly specify the project when running CLI commands:bash
ng serve your-main-project-name ng build your-secondary-project
Why This Works
The defaultProject
property was deprecated in Angular CLI v6+ (GitHub Issue #11111) and became non-functional. Newer CLI versions treat it as an invalid workspace extension, causing the error. Removing it aligns your configuration with current Angular standards.
WARNING
Manually adding defaultProject
to newer Angular projects creates conflicts. The CLI automatically uses your first project as default.
Best Practices
- Avoid manual edits to
angular.json
: Use CLI commands likeng new
orng generate application
to manage projects - Verify Angular CLI version: Ensure you’re using a recent version (check with
ng version
) - Version control: Commit changes before modifying configuration files for easy rollback
Summary:
Eliminating the obsolete defaultProject
from angular.json
resolves this error immediately. The Angular CLI no longer supports this property, and your project will function correctly without it regardless of its type or complexity.