mastra-ai/mastra · error · Error
Project not found: ${wanted}
Error message
Project not found: ${wanted} What it means
Thrown by `resolveProject` in the `mastra env` command family when a project was explicitly requested (via --project flag or MASTRA_PROJECT_ID) but no project in the authenticated organization matches that id, name, or slug. The lookup fetches all projects for the org and requires an exact match on one of the three identifiers.
Source
Thrown at packages/cli/src/commands/env/resolve-project.ts:18
import { loadProjectConfig } from '../studio/project-config.js';
import type { Project } from './platform-api.js';
import { fetchProjects } from './platform-api.js';
/**
* Resolve the target project for env-group commands without requiring a
* positional argument. Resolution order: `MASTRA_PROJECT_ID` env var,
* `--project` flag, then the `.mastra-project.json` written by
* `mastra deploy` in the current directory.
*/
export async function resolveProject(token: string, orgId: string, projectArg?: string): Promise<Project> {
const projects = await fetchProjects(token, orgId);
const wanted = process.env.MASTRA_PROJECT_ID ?? projectArg;
if (wanted) {
const project = projects.find(proj => proj.id === wanted || proj.name === wanted || proj.slug === wanted);
if (!project) {
throw new Error(`Project not found: ${wanted}`);
}
return project;
}
const config = await loadProjectConfig(process.cwd());
if (config?.projectId) {
const project = projects.find(proj => proj.id === config.projectId);
if (project) return project;
}
throw new Error(
'No project specified. Pass --project <name|slug|id>, set MASTRA_PROJECT_ID, or run from a directory with a linked .mastra-project.json.',
);
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Run `mastra project list` (or check the Mastra Cloud dashboard) and copy the exact project id/name/slug, then retry
- Unset or fix MASTRA_PROJECT_ID (check shell env and .env files) — `unset MASTRA_PROJECT_ID` or set the correct id
- Confirm you're authenticated to the right org: re-run `mastra auth login` / verify MASTRA_ORG_ID
- If the project was renamed or deleted, recreate/relink it or point at the new slug
- Re-link the local directory: ensure .mastra-project.json contains a valid projectId
Example fix
// before mastra env vars pull --project my-projekt // after (exact slug from dashboard) mastra env vars pull --project my-project
Defensive patterns
Strategy: validation
Validate before calling
import { config } from 'dotenv';
config();
const projectId = process.env.MASTRA_PROJECT_ID;
if (projectId && !/^prj_[A-Za-z0-9]+$/.test(projectId)) {
throw new Error(`MASTRA_PROJECT_ID="${projectId}" does not look like a valid project id`);
}
if (!projectId && !process.argv.includes('--project')) {
throw new Error('Set MASTRA_PROJECT_ID or pass --project before running mastra env');
} Type guard
function isResolvedProject(p: unknown): p is { id: string; name: string; slug: string } {
return typeof p === 'object' && p !== null &&
typeof (p as any).id === 'string' && (p as any).id.length > 0 &&
typeof (p as any).slug === 'string';
} Try / catch
try {
const project = await resolveProject({ project: argv.project });
} catch (err) {
if (err instanceof Error && err.message.startsWith('Project not found:')) {
console.error(`${err.message}. Run \`mastra project list\` for valid ids/slugs and check MASTRA_PROJECT_ID / org login.`);
process.exitCode = 1;
return;
}
throw err;
} Prevention
- Commit or template .mastra-project.json so every checkout is linked
- Keep MASTRA_PROJECT_ID in per-project .env, never in global shell profile
- Copy ids/slugs directly from the dashboard instead of typing names
- Re-login when switching organizations to avoid looking in the wrong org
- Use slugs in scripts — they are human-readable and stable across renames of ids
When it happens
Trigger: Calling any `mastra env ...` command with `--project <value>` or MASTRA_PROJECT_ID set to a value that is not the id, name, or slug of any project in the current org (checked via fetchProjects with the auth token and org id).
Common situations: Typo in the project name/slug; project deleted or renamed in Mastra Cloud; MASTRA_PROJECT_ID stale in .env from another org/account; being authenticated against the wrong organization so the project isn't in the fetched list; using a display name with different casing.
Related errors
- No project specified. Pass --project <name|slug|id>, set MAS
- No environments found for this project. Deploy first with `m
- Multiple environments found (${slugs}). Specify one: mastra
- MISSING_TSCONFIG
- 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/941c21ed6fc0b9d4.
Report an issue: GitHub.