angular/angular-cli · error · SchematicsException

Option "project" is required.

Error message

Option "project" is required.

What it means

The @angular/pwa schematic requires an explicit target project when the workspace contains more than one project, or when the --project option is absent. The schematic throws SchematicsException to fail fast before reading workspace configuration further. It prevents silently adding PWA files to an unintended project.

Source

Thrown at packages/angular/pwa/pwa/index.ts:74

      const chunks = [];
      for await (const chunk of source) {
        chunks.push(Buffer.from(chunk));
      }
      host.overwrite(path, Buffer.concat(chunks));
    });
  };
}

export default function (options: PwaOptions): Rule {
  return async (host) => {
    if (!options.title) {
      options.title = options.project;
    }

    const workspace = await readWorkspace(host);

    if (!options.project) {
      throw new SchematicsException('Option "project" is required.');
    }

    const project = workspace.projects.get(options.project);
    if (!project) {
      throw new SchematicsException(`Project is not defined in this workspace.`);
    }

    if (project.extensions['projectType'] !== 'application') {
      throw new SchematicsException(`PWA requires a project type of "application".`);
    }

    // Find all the relevant targets for the project
    if (project.targets.size === 0) {
      throw new SchematicsException(`Targets are not defined for this project.`);
    }

    const buildTargets = [];
    const testTargets = [];

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Re-run with an explicit project: ng add @angular/pwa --project my-app
  2. Verify the project name in angular.json (projects key) matches the value passed to --project
  3. Set 'defaultProject'/'cli.defaultProject' or pass the project interactively when prompted
  4. If calling the schematic in code, pass { project: '<name>' } in options

Example fix

// before
ng generate @angular/pwa
// after
ng generate @angular/pwa --project frontend-app
Defensive patterns

Strategy: validation

Validate before calling

import { workspaces } from '@angular-devkit/core';
const ws = await workspaces.readWorkspace('angular.json');
if (!options.project) throw new Error('Pass --project; available: ' + [...ws.projects.keys()].join(', '));

Type guard

function hasProject(o: { project?: string }): o is { project: string } {
  return typeof o.project === 'string' && o.project.length > 0;
}

Try / catch

try {
  await schematicRunner.runSchematic('pwa', { project: 'my-app' });
} catch (e) {
  if (e instanceof SchematicsException && e.message.includes('Option "project"')) {
    console.error('Supply --project with a name from angular.json');
  }
}

Prevention

When it happens

Trigger: Running `ng add @angular/pwa` (or the pwa schematic) without --project in a multi-project workspace, or invoking the schematic programmatically with options.project undefined.

Common situations: Nx or ng multi-app workspaces, custom CI scripts calling the schematic without options, renamed projects so default project no longer matches.

Related errors


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