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
In non-interactive (--yes) deploys, resolveProject only auto-selects an existing project when exactly one project's name/slug matches the local package.json name. When the org has other projects and none (or more than one) match, the command throws rather than deploying to the wrong project, and asks you to pass --project or run interactively.
Source
Thrown at packages/cli/src/commands/studio/deploy.ts:324
projectSlug: projectConfig.projectSlug ?? projectConfig.projectName ?? projectConfig.projectId,
};
}
// 3. Consult the list of existing projects in this org before defaulting to create-new.
const projects = await fetchProjects(token, orgId);
const nameMatches = defaultName
? projects.filter(proj => proj.name === defaultName || proj.slug === defaultName)
: [];
if (projects.length > 0) {
if (autoAccept) {
// Non-interactive: only safe to auto-pick when there is exactly one
// project whose name/slug matches the package.json name.
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
- Pass --project with the target project's id or slug: `mastra studio deploy --project my-project-slug`
- Re-run without --yes and select the project interactively
- Align package.json `name` with the existing Studio project name/slug so auto-matching succeeds
- Delete obsolete projects in the Studio UI if the ambiguity comes from stale duplicates
Example fix
// before mastra studio deploy --yes // Error: Found 3 existing project(s) in this organization... // after mastra studio deploy --yes --project my-api
Defensive patterns
Strategy: validation
Validate before calling
const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
const projects = await fetchProjects(orgId);
const matches = projects.filter(p => p.name === pkg.name || p.slug === pkg.name);
if (projects.length > 0 && matches.length !== 1 && !process.argv.includes('--project')) {
throw new Error('Pass --project <id-or-slug> or run interactively.');
} Type guard
function hasUniqueProjectMatch(projects: Project[], name: string): projects is [Project, ...Project[]] & { length: 1 } {
return projects.filter(p => p.name === name || p.slug === name).length === 1;
} Try / catch
try {
await studioDeploy({ yes: true });
} catch (e) {
if (e instanceof Error && e.message.includes('existing project(s) in this organization')) {
console.error('Run with --project <id-or-slug> or drop --yes to pick interactively.');
process.exitCode = 2;
} else throw e;
} Prevention
- Keep package.json `name` identical to the Studio project name/slug
- Always pass --project explicitly in CI/automation
- Clean up stale projects in the Studio org to avoid ambiguous name matches
- Avoid renaming package.json without updating the Studio project
When it happens
Trigger: `mastra studio deploy --yes` against an org that already contains projects, where the local package.json `name` does not uniquely match one project's name or slug (zero matches, or the name matches multiple projects).
Common situations: Renaming package.json `name` after the project was created; reusing an org with many pre-existing projects; monorepo package names diverging from Studio project names; duplicate similarly-named projects causing ambiguous matches.
Related errors
- Invalid --region "${region}". Expected one of: eu, us.
- No organization matched --org "${value}". Available: ${avail
- You have no organizations. Please create one at ${MASTRA_STU
- Found ${projects.length} existing project(s) in this organiz
- Could not determine project name from package.json. Use --pr
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/9243c50f058abc79.
Report an issue: GitHub.