mastra-ai/mastra · error

Found ${existing.length} existing project(s) in this organiz

Error message

Found ${existing.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.

What it means

In non-interactive (--yes) deploys, resolveProject will only auto-pick a project when exactly one existing project in the organization matches the derived name/slug. If any projects exist but none (or more than one) match the name, it refuses to guess and throws, telling you to select explicitly.

Source

Thrown at packages/cli/src/commands/server/deploy.ts:301

    };
  }

  const name = defaultName;
  if (!name) {
    throw new Error('Could not determine project name from package.json. Use --project to specify one.');
  }

  const existing = await fetchServerProjects(token, orgId);
  const nameMatches = existing.filter(proj => proj.name === name || proj.slug === name);

  if (existing.length > 0) {
    if (autoAccept) {
      // Non-interactive: only safe to auto-pick when exactly one project matches by name/slug.
      if (nameMatches.length === 1) {
        const m = nameMatches[0]!;
        return { projectId: m.id, projectName: m.name, projectSlug: m.slug ?? m.name };
      }
      throw new Error(
        `Found ${existing.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.`,
      );
    }

    const CREATE_NEW = '__create_new__';
    const initialValue = nameMatches.length === 1 ? nameMatches[0]!.id : existing[0]!.id;
    const selected = await p.select({
      message: 'Select a project to deploy to',
      initialValue,
      options: [
        ...existing.map(proj => ({ value: proj.id, label: `${proj.name} (${proj.id})` })),
        { value: CREATE_NEW, label: `+ Create new project "${name}"` },
      ],
    });

    if (p.isCancel(selected)) {
      p.cancel('Deploy cancelled.');
      process.exit(0);

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass the target explicitly: `mastra server deploy --yes --project <id-or-slug>`
  2. Re-run interactively without --yes and pick the project from the prompt
  3. Set MASTRA_PROJECT_ID to the project id in CI secrets
  4. Align package.json "name" (or the project slug) with exactly one existing project

Example fix

// before (CI script)
mastra server deploy --yes
// after
mastra server deploy --yes --project "$MASTRA_PROJECT_ID"
Defensive patterns

Strategy: validation

Validate before calling

// CI guard: fail fast unless exactly one project target is pinned
if (process.env.CI && !process.env.MASTRA_PROJECT_ID) {
  throw new Error('CI deploys must set MASTRA_PROJECT_ID (or pass --project).');
}

Type guard

function isPinnedTarget(opts: { project?: string }): boolean {
  return typeof opts.project === 'string' && opts.project.length > 0 ||
    typeof process.env.MASTRA_PROJECT_ID === 'string' && process.env.MASTRA_PROJECT_ID.length > 0;
}

Try / catch

try {
  await exec('mastra server deploy --yes');
} catch (err) {
  if (err instanceof Error && /existing project\(s\) in this organization/.test(err.message)) {
    await exec(`mastra server deploy --yes --project ${REQUIRED_PROJECT_ID}`);
  } else throw err;
}

Prevention

When it happens

Trigger: Running `mastra server deploy --yes` when the org already contains projects and either (a) no project's name or slug equals the default name from package.json, or (b) multiple projects share that name. With zero existing projects this error is not thrown (it creates a new one).

Common situations: CI pipelines with --yes on a fresh checkout where package.json name differs from the deployed project's name; renamed package in package.json so the slug no longer matches; organizations with several similarly named projects causing ambiguous matches.

Related errors


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