angular/angular-cli · error · Error

Invalid value for argument: ${key}, Given: '${pair}', Expect

Error message

Invalid value for argument: ${key}, Given: '${pair}', Expected key=value pair

What it means

Some CLI options accept an array of key=value strings (e.g. ng g component --export-symbols=... or configuration pair options). checkStringMap validates each provided pair contains '='; a bare value without '=' is rejected with this error naming the argument key.

Source

Thrown at packages/angular/cli/src/command-builder/utilities/json-schema.ts:75

 * @param keyValuePairOptions A set of options that should be in the form of `key=value`.
 * @param args The parsed arguments.
 * @returns `true` if the options are valid, otherwise an error is thrown.
 */
function checkStringMap(keyValuePairOptions: Set<string>, args: Arguments): boolean {
  for (const key of keyValuePairOptions) {
    const value = args[key];
    if (!Array.isArray(value)) {
      // Value has been parsed.
      continue;
    }

    for (const pair of value) {
      if (pair === undefined) {
        continue;
      }

      if (!pair.includes('=')) {
        throw new Error(
          `Invalid value for argument: ${key}, Given: '${pair}', Expected key=value pair`,
        );
      }
    }
  }

  return true;
}

/**
 * A Yargs coerce function that converts an array of `key=value` strings to an object.
 * @param value An array of `key=value` strings.
 * @returns An object with the keys and values from the input array.
 */
function coerceToStringMap(
  value: (string | undefined)[],
): Record<string, string> | (string | undefined)[] {
  const stringMap: Record<string, string> = {};

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Use key=value form: --myOption key=value
  2. Quote the whole pair when it contains spaces: --myOption "key=some value"
  3. Check the option name in 'ng command --help' to confirm it expects key=value pairs
  4. Fix wrapping scripts that re-split arguments and drop the '='

Example fix

// before
ng g c card --style scss
# where option expects pairs
// after
ng g c card --style=scss  # or --myMap key=value
Defensive patterns

Strategy: validation

Validate before calling

function validatePairs(key: string, values: string[]): void {
  for (const pair of values) {
    if (pair !== undefined && !pair.includes('=')) {
      throw new Error(`${key} expects key=value, got: ${pair}`);
    }
  }
}
validatePairs('--myOption', parsedArgs);

Try / catch

try {
  execSync(`ng ${cmd} ${args.join(' ')}`, { stdio: 'inherit' });
} catch (e) {
  if (String(e).includes('Expected key=value pair')) {
    const pair = String(e).match(/Given: '(.+)'/)?.[1];
    console.error(`Fix argument to key=value form: ${pair}`);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing an option like --some-map foo (no =) or a quoted value where the '=' got swallowed by the shell, when the schema declares the option as a string-array/record type.

Common situations: Shell quoting issues (spaces splitting the pair), forgetting '=' in flags like --configuration-key value vs key=value, typos like --env=dev written as --env dev on map-typed options.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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