angular/angular-cli · error · Error

path option is required

Error message

path option is required

What it means

writeJsonWorkspace can serialize a workspace in two modes. In update mode it can infer the output path from the metadata; in direct-serialize mode (when no updater produced metadata), it has no way to know where to write, so a `path` option is mandatory. Passing no path in the non-update path throws this error.

Source

Thrown at packages/angular_devkit/core/src/workspace/json/writer.ts:42

  path?: string,
  options: {
    schema?: string;
  } = {},
): Promise<void> {
  const metadata = (workspace as JsonWorkspaceDefinition)[JsonWorkspaceSymbol];

  if (metadata) {
    if (!metadata.hasChanges) {
      return;
    }
    // update existing JSON workspace
    const data = updateJsonWorkspace(metadata);

    return host.writeFile(path ?? metadata.filePath, data);
  } else {
    // serialize directly
    if (!path) {
      throw new Error('path option is required');
    }

    const obj = convertJsonWorkspace(workspace, options.schema);
    const data = JSON.stringify(obj, null, 2);

    return host.writeFile(path, data);
  }
}

function convertJsonWorkspace(workspace: WorkspaceDefinition, schema?: string): JsonObject {
  const obj = {
    $schema: schema || './node_modules/@angular/cli/lib/config/schema.json',
    version: 1,
    ...workspace.extensions,
    ...(isEmpty(workspace.projects)
      ? {}
      : { projects: convertJsonProjectCollection(workspace.projects) }),
  };

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Pass the target file path in the options: writeJsonWorkspace(workspace, host, { path: 'angular.json' })
  2. Or provide an updater function so updateJsonWorkspace mode is used and the original metadata.filePath is used
  3. If wrapping this API, default the path from workspace.definition.filePath before calling

Example fix

// before
await writeJsonWorkspace(workspace, host, {});
// after
await writeJsonWorkspace(workspace, host, { path: 'angular.json' });
Defensive patterns

Strategy: validation

Validate before calling

function assertWriteOptions(opts) {
  if (!opts || !(typeof opts.path === 'string' || typeof opts.updater === 'function')) {
    throw new Error('writeJsonWorkspace requires `path` or an updater.');
  }
}

Type guard

function hasPath(o) {
  return typeof o === 'object' && o !== null && typeof o.path === 'string' && o.path.length > 0;
}

Try / catch

try {
  await writeJsonWorkspace(workspace, host, opts);
} catch (err) {
  if (err.message === 'path option is required') {
    await writeJsonWorkspace(workspace, host, { ...opts, path: 'angular.json' });
  } else throw err;
}

Prevention

When it happens

Trigger: Calling writeJsonWorkspace(workspace, host, { /* no `path` */ }) without an updater function that produces metadata with a filePath — i.e. serializing the workspace directly via convertJsonWorkspace without specifying where to write.

Common situations: Script that reads a workspace, modifies it via convertJsonWorkspace, and calls the writer forgetting the path option; refactors that removed the updater (and thus the metadata filePath) but left the options object unchanged.

Related errors


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