angular/angular-cli · error · SchematicsException

Web Worker requires a project type of "application".

Error message

Web Worker requires a project type of "application".

What it means

Web workers can only be generated in projects whose projectType extension is "application". The web-worker schematic checks project.extensions['projectType'] and throws this SchematicsException for libraries or any non-application project, because worker bundling wiring assumes an application build.

Source

Thrown at packages/schematics/angular/web-worker/index.ts:81

} else {
  // Web Workers are not supported in this environment.
  // You should add a fallback so that your program still executes correctly.
}
    `;

    // Append the worker creation snippet.
    const originalContent = host.readText(siblingModulePath);
    host.overwrite(siblingModulePath, originalContent + '\n' + workerCreationSnippet);

    return host;
  };
}

const webWorkerSchematic: RuleFactory<WebWorkerOptions> = createProjectSchematic(
  (options, { project }) => {
    const projectType = project.extensions['projectType'];
    if (projectType !== 'application') {
      throw new SchematicsException(`Web Worker requires a project type of "application".`);
    }

    if (options.path === undefined) {
      options.path = buildDefaultPath(project);
    }
    const parsedPath = parseName(options.path, options.name);
    options.name = parsedPath.name;
    options.path = parsedPath.path;

    const templateSourceWorkerCode = apply(url('./files/worker'), [
      applyTemplates({ ...options, ...strings }),
      move(parsedPath.path),
    ]);

    const root = project.root || '';
    const templateSourceWorkerConfig = apply(url('./files/worker-tsconfig'), [
      applyTemplates({
        ...options,

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Target an application project instead: `ng g web-worker my-worker --project=my-app`.
  2. If the worker truly belongs to a library, generate it in a consuming application or structure the worker as a plain worker file/lib asset without the schematic.
  3. Check the project's projectType in angular.json; only change it to "application" if the project genuinely is one.

Example fix

// before
ng g web-worker app-worker --project=my-lib   // projectType: library
// after
ng g web-worker app-worker --project=my-app   // projectType: application
Defensive patterns

Strategy: validation

Validate before calling

const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));
const projectType = ws.projects?.[name]?.projectType ?? ws.projects?.[name]?.extensions?.projectType;
if (projectType !== 'application') {
  throw new Error(`Web workers can only be added to "application" projects; "${name}" is "${projectType}".`);
}

Prevention

When it happens

Trigger: Running `ng generate web-worker <name> --project=<name>` where the project's angular.json entry has "projectType": "library" (or anything other than "application").

Common situations: Trying to add a web worker inside a library project, an Nx workspace lib, or after hand-editing projectType to a non-standard value.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/5532158624729de2. Report an issue: GitHub.