mastra-ai/mastra · error

Invalid --region "${region}". Expected one of: eu, us.

Error message

Invalid --region "${region}". Expected one of: eu, us.

What it means

parseProjectRegion in mastracode/mastra-factory/src/create.ts is the CLI validator for the `--region` flag of `create`. The region must be exactly 'eu' or 'us' (the keys of the REGION_CLUSTER map, typed as ProjectRegion); anything else throws immediately at argument-parse time, before any scaffolding or provisioning happens.

Source

Thrown at mastracode/mastra-factory/src/create.ts:65

  orgName: string;
  project: PlatformProject;
  secretKey: string;
  databaseUrl: string;
}

const PROJECT_REGION_OPTIONS = [
  { value: 'eu', label: '🇪🇺 eu' },
  { value: 'us', label: '🇺🇸 us' },
] as const satisfies ReadonlyArray<{ value: ProjectRegion; label: string }>;

const NEON_REGION_BY_PROJECT_REGION = {
  eu: 'aws-eu-central-1',
  us: 'aws-us-west-2',
} as const satisfies Record<ProjectRegion, string>;

function parseProjectRegion(region: string): ProjectRegion {
  if (region === 'eu' || region === 'us') return region;
  throw new Error(`Invalid --region "${region}". Expected one of: eu, us.`);
}

export async function create(args: CreateArgs): Promise<void> {
  p.intro(color.inverse(' Mastra Factory '));

  const requestedRegion = args.region ? parseProjectRegion(args.region) : undefined;
  const projectName =
    args.projectName ??
    (await p.text({
      message: 'What do you want to name your project?',
      placeholder: 'my-mastra-factory',
      validate: value => {
        if (!value?.trim()) return `Project name can't be empty`;
        if (fs.existsSync(path.resolve(value.trim()))) return `Directory ${value.trim()} already exists`;
        return undefined;
      },
    }));

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Use exactly --region eu or --region us (lowercase, no quotes variation).
  2. Map any legacy/verbose region (e.g. 'aws-eu-central-1' → 'eu', 'aws-us-west-2' → 'us') before passing the flag.
  3. Trim/lowercase the value in your wrapper script or CI config before invoking the CLI.
  4. Run the CLI without --region if a default region is acceptable (requestedRegion is only parsed when args.region is set).

Example fix

// before
pnpm create mastra-factory my-app --region aws-eu-central-1
// after
pnpm create mastra-factory my-app --region eu
Defensive patterns

Strategy: validation

Validate before calling

const REGIONS = ['eu', 'us'] as const;
type Region = (typeof REGIONS)[number];
function assertRegion(v: string): asserts v is Region {
  if (!(REGIONS as readonly string[]).includes(v)) throw new Error(`Invalid --region "${v}". Expected one of: eu, us.`);
}

Type guard

function isProjectRegion(v: string): v is 'eu' | 'us' {
  return v === 'eu' || v === 'us';
}

Try / catch

// parse-time error; validate before invoking the CLI instead of catching
let region: 'eu' | 'us' | undefined;
if (args.region) {
  const normalized = args.region.trim().toLowerCase();
  if (!isProjectRegion(normalized)) {
    console.error(`Region "${args.region}" not supported; use eu or us.`);
    process.exit(2);
  }
  region = normalized;
}

Prevention

When it happens

Trigger: Running the create CLI with --region set to anything other than the exact strings 'eu' or 'us': typos ('eu-west', 'EU', 'us-east-1'), a region copied from an AWS console name, an empty string (--region=""), or a flag value consumed from an env var/ci config holding a legacy value.

Common situations: CI pipeline config still referencing an old region identifier after the factory narrowed choices to eu/us; users pasting the AWS cluster name ('aws-eu-central-1') instead of the short alias; case-sensitivity surprises on macOS/Windows shells; documentation examples that predate the eu/us restriction.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/2f28862826a51372. Report an issue: GitHub.