angular/angular-cli · error · SchematicsException
Service worker requires a project type of "application".
Error message
Service worker requires a project type of "application".
What it means
Thrown by the service-worker schematic when the target project's projectType extension is not "application". Service workers only apply to application builds (index.html + production build output), so the schematic rejects libraries.
Source
Thrown at packages/schematics/angular/service-worker/index.ts:111
code`${external('provideServiceWorker', '@angular/service-worker')}('ngsw-worker.js', {
enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000'
})`,
);
};
}
function getTsSourceFile(host: Tree, path: string): ts.SourceFile {
const content = host.readText(path);
const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
return source;
}
const serviceWorkerSchematic: RuleFactory<ServiceWorkerOptions> = createProjectSchematic(
async (options, { project, workspace, tree, context: { logger } }) => {
if (project.extensions.projectType !== 'application') {
throw new SchematicsException(`Service worker requires a project type of "application".`);
}
const buildTarget = project.targets.get('build');
if (!buildTarget) {
throw targetBuildNotFoundError();
}
const buildOptions = buildTarget.options as Record<string, string | boolean>;
const browserEntryPoint = await getMainFilePath(tree, options.project);
const ngswConfigPath = join(project.root, 'ngsw-config.json');
if (
buildTarget.builder === Builders.Application ||
buildTarget.builder === Builders.BuildApplication
) {
const productionConf = buildTarget.configurations?.production;
if (productionConf) {
productionConf.serviceWorker = ngswConfigPath;
} else {View on GitHub (pinned to bb72145f9a)
Solutions
- Run the schematic against an application: `ng g @angular/pwa --project <app-name>`.
- Set "projectType": "application" in angular.json if the project truly is an application but misconfigured.
- Do not add a service worker to libraries; configure PWA at the application level.
- Confirm targets with `ng list` before running.
Example fix
// before ng g @angular/pwa --project ui-lib // after ng g @angular/pwa --project storefront
Defensive patterns
Strategy: validation
Validate before calling
const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));
const p = ws.projects?.[projectName];
if (p?.projectType !== 'application') {
throw new Error(`Service worker requires an application project; '${projectName}' is not one.`);
} Type guard
function isApplicationProject(p: { projectType?: string } | undefined): p is { projectType: 'application' } {
return p?.projectType === 'application';
} Try / catch
try {
await generateServiceWorkerSchematic({ project: projectName });
} catch (e) {
if (String(e.message).includes('project type of "application"')) {
console.error(`Pass an application via --project; '${projectName}' is a library.`);
} else throw e;
} Prevention
- Add PWA/service-worker only to application projects
- Confirm projectType before running project-scoped schematics
- Avoid typos in --project in multi-project workspaces
- Keep custom angular.json entries with correct projectType
When it happens
Trigger: Running `ng g @angular/pwa --project <lib>` (or the serviceWorkerSchematic Rule) against a project whose project.extensions.projectType is 'library' or undefined.
Common situations: Attempting to add PWA/service-worker to a library; custom projects in angular.json missing the projectType extension; wrong --project name in a multi-project workspace selecting a library.
Related errors
- Server schematic requires a project type of "application".
- Could not find "@angular/core" version.
- No "production" configuration found for build target. The "s
- Option "project" is required.
- Project is not defined in this workspace.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/055b4e9d4c1faa1e.
Report an issue: GitHub.