ReactiveX/rxjs · error · Error

--out-dir is required with --write

Error message

--out-dir is required with --write

What it means

Thrown by validateArguments when --write is set but --out-dir (which populates outputRoot) is not. The tool refuses to write in-place, so dry-run planning needs no output directory but an actual write requires an explicit destination.

Source

Thrown at packages/migrate/src/cli.ts:173

        options.help = true;
        break;
      default:
        if (argument.startsWith('-')) throw new Error(`Unknown option: ${argument}`);
        options.files.push(argument);
    }
  }
  return options;
}

function validateArguments(options: CliOptions): asserts options is RunnableCliOptions {
  const missing = [
    options.files.length === 0 ? 'at least one source file' : undefined,
    options.sourceRoot ? undefined : '--source-root',
    options.repository ? undefined : '--source-repo',
    options.sha ? undefined : '--source-sha',
  ].filter((value): value is string => value !== undefined);
  if (missing.length > 0) throw new Error(`Missing required argument${missing.length === 1 ? '' : 's'}: ${missing.join(', ')}`);
  if (options.write && !options.outputRoot) throw new Error('--out-dir is required with --write');
}

function requiredValue(argv: readonly string[], index: number, option: string): string {
  const value = argv[index];
  if (!value || value.startsWith('-')) throw new Error(`${option} requires a value`);
  return value;
}

function errorReport(code: MigrationCliErrorReport['error']['code'], message: string): MigrationCliErrorReport {
  return { schemaVersion: migrationCliReportSchemaVersion, status: 'error', error: { code, message } };
}

function writeJson(stream: Pick<NodeJS.WriteStream, 'write'>, value: MigrationCliReport | MigrationCliErrorReport): void {
  stream.write(`${JSON.stringify(value, null, 2)}\n`);
}

function messageFor(error: unknown): string {
  return error instanceof Error ? error.message : String(error);

View on GitHub (pinned to 54796b38a5)

Solutions

  1. Add --out-dir <path> alongside --write
  2. If you only want a plan/report, remove --write
  3. Verify the --out-dir value is not empty or misparsed

Example fix

# before
npx @rxjs/migrate --write spec/app.spec.ts
# after
npx @rxjs/migrate --write --out-dir migrated spec/app.spec.ts
Defensive patterns

Strategy: validation

Validate before calling

if (write && !outputRoot) throw new Error('Pass --out-dir when using --write');

Type guard

const canWrite = (o: {write:boolean; outputRoot?:string}): boolean => !o.write || !!o.outputRoot;

Try / catch

try { runCli(argv); } catch (e) { console.error((e as Error).message); }

Prevention

When it happens

Trigger: Running the CLI with --write but no --out-dir flag (or an --out-dir value that failed to parse).

Common situations: Assuming the tool overwrites source files in place like other codemods, or adding --write to an existing plan-only command without also adding the output directory.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of ReactiveX/rxjs@54796b38a5 (2026-08-28). Data as JSON: /api/errors/fac25c426c4c38fd. Report an issue: GitHub.