angular/angular-cli · error

Invalid target: ${JSON.stringify(target)}.

Error message

Invalid target: ${JSON.stringify(target)}.

What it means

The ..getTargetOptions job handler asks the ArchitectHost for options of a given Target object. If the host returns null (no such project/target combination exists in the workspace), it throws 'Invalid target: ...' with the JSON of the target.

Source

Thrown at packages/angular_devkit/architect/src/architect.ts:271

            if (builderInfo === null) {
              return of(null);
            }

            return this._createBuilder(builderInfo, target, options);
          }),
        );
      }),
      first(null, null),
    ) as Observable<JobHandler<A, I, O> | null>;
  }
}

function _getTargetOptionsFactory(host: ArchitectHost) {
  return createJobHandler<Target, json.JsonValue, json.JsonObject>(
    (target) => {
      return host.getOptionsForTarget(target).then((options) => {
        if (options === null) {
          throw new Error(`Invalid target: ${JSON.stringify(target)}.`);
        }

        return options;
      });
    },
    {
      name: '..getTargetOptions',
    },
  );
}

function _getProjectMetadataFactory(host: ArchitectHost) {
  return createJobHandler<Target, json.JsonValue, json.JsonObject>(
    (target) => {
      return host.getProjectMetadata(target).then((options) => {
        if (options === null) {
          throw new Error(`Invalid target: ${JSON.stringify(target)}.`);
        }

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Verify the project and target names against angular.json (projects.<name>.architect.<target>)
  2. Use targetFromTargetString with the exact 'project:target' specifier from your config
  3. Check the JSON in the error to see which field is wrong
  4. Regenerate/fix angular.json if the target was renamed (e.g. 'build' vs 'browser')

Example fix

// before
architect.getTargetOptions({ project: 'app', target: 'servee' })
// after
architect.getTargetOptions({ project: 'app', target: 'serve' })
Defensive patterns

Strategy: validation

Validate before calling

const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));
const opts = ws.projects?.[target.project]?.architect?.[target.target];
if (!opts) throw new Error(`Unknown target ${target.project}:${target.target}`);

Type guard

function targetExists(ws, target) {
  return !!ws?.projects?.[target?.project]?.architect?.[target?.target];
}

Try / catch

try {
  const options = await architect.getTargetOptions(target);
} catch (e) {
  if (e.message.startsWith('Invalid target:')) {
    console.error(`No such project/target in workspace: ${e.message}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling architect.getTargetOptions(target) (or scheduling it) with a target whose project or target name does not exist in angular.json / the host's project registry.

Common situations: Typos in project or target names; targets removed after angular.json refactors; hardcoding targets that only exist in one workspace configuration; calling before workspace loading completes.

Related errors


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