mastra-ai/mastra · error · Error

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

Error message

Found ${projects.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

When deploying with --yes (auto-accept) and the organization already contains projects, resolveProject cannot silently pick a target. It only auto-selects when exactly one project matches the package name; otherwise it throws, telling you to pass --project <id-or-slug> or drop --yes for an interactive picker. This prevents accidental deploys to the wrong existing project.

Source

Thrown at packages/cli/src/commands/deploy/index.ts:231

      existing: true,
      projectId: projectConfig.projectId,
      projectName: projectConfig.projectName ?? projectConfig.projectId,
      projectSlug: projectConfig.projectSlug ?? projectConfig.projectName ?? projectConfig.projectId,
    };
  }

  const projects = await fetchProjects(token, orgId);
  const nameMatches = defaultName
    ? projects.filter(proj => proj.name === defaultName || proj.slug === defaultName)
    : [];

  if (projects.length > 0) {
    if (autoAccept) {
      if (nameMatches.length === 1) {
        const m = nameMatches[0]!;
        return { existing: true, projectId: m.id, projectName: m.name, projectSlug: m.slug ?? m.name };
      }
      throw new Error(
        `Found ${projects.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 : projects[0]!.id;
    const selected = await p.select({
      message: 'Select a project to deploy to',
      initialValue,
      options: [
        ...projects.map(proj => ({
          value: proj.id,
          label: `${proj.name} (${proj.id})`,
        })),
        { value: CREATE_NEW, label: defaultName ? `+ Create new project "${defaultName}"` : '+ Create new project' },
      ],
    });

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass --project <id-or-slug> explicitly to pin the target project
  2. Re-run without --yes and select the project interactively
  3. Rename the project entry in package.json to exactly match the intended existing project so auto-selection works
  4. In CI, hardcode the project id/slug in the deploy command rather than relying on name matching

Example fix

// before
mastra deploy --yes  // 3 projects, name matches 0 -> error
// after
mastra deploy --yes --project my-service-slug
Defensive patterns

Strategy: validation

Validate before calling

// Pin the target project explicitly in non-interactive contexts
if (autoAccept && !opts.project) {
  throw new Error('Pass --project <id-or-slug> when using --yes with existing projects in the org');
}

Type guard

function hasSingleNameMatch(nameMatches: Array<{ id: string }>): nameMatches is [ { id: string } ] {
  return nameMatches.length === 1;
}

Try / catch

try {
  await deploy(opts);
} catch (err) {
  if (err instanceof Error && err.message.includes('existing project(s)')) {
    console.error('Re-run with --project <id-or-slug> or omit --yes to choose interactively');
  } else throw err;
}

Prevention

When it happens

Trigger: Deploy invoked with --yes where projects.length > 0 and either zero or multiple name matches exist (nameMatches.length !== 1) — i.e., ambiguity between existing projects that auto-accept cannot resolve.

Common situations: CI pipelines with --yes where package.json name doesn't match any existing project, or matches several; reusing one org for many similarly-named services; renamed package.json so the name no longer matches the intended project.

Related errors


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