mastra-ai/mastra · error · Error
No environments found for this project. Deploy first with `m
Error message
No environments found for this project. Deploy first with `mastra deploy`.
What it means
Thrown by `pickEnvironment` during `mastra env vars pull` when the API returns an empty environments array for the resolved project. Mastra Cloud creates environments as a side effect of deploying, so a project with zero environments has never been deployed.
Source
Thrown at packages/cli/src/commands/env/vars.ts:33
const vars = env.command('vars').description("Manage an environment's variables");
vars
.command('pull')
.description('Pull the merged env vars (environment + project scope) into a local env file')
.argument('[environment]', 'Environment name, slug, or ID (optional when the project has exactly one)')
.option('--project <project>', 'Project name, slug, or ID (default: linked project)')
.option('-o, --output <file>', 'File to write (default: .env)')
.option('-f, --force', 'Overwrite an existing output file')
.action(wrapAction(envVarsPullAction));
}
function isAlreadyExistsError(error: unknown): boolean {
return typeof error === 'object' && error !== null && 'code' in error && error.code === 'EEXIST';
}
function pickEnvironment(environments: Environment[], envArg: string | undefined): Environment {
if (environments.length === 0) {
throw new Error('No environments found for this project. Deploy first with `mastra deploy`.');
}
if (!envArg) {
if (environments.length === 1) return environments[0]!;
const slugs = environments.map(e => e.slug).join(', ');
throw new Error(`Multiple environments found (${slugs}). Specify one: mastra env vars pull <environment>`);
}
const env = environments.find(e => e.id === envArg || e.name === envArg || e.slug === envArg);
if (!env) {
throw new Error(`Environment not found: ${envArg}`);
}
return env;
}
/**
* Pull the full set of env vars that a deploy of the target environment
* actually runs with — the environment row's vars (e.g. added via the UIView on GitHub (pinned to 75dd419e61)
Solutions
- Deploy the project first: run `mastra deploy` (or trigger your CI deploy pipeline), then retry the pull
- Verify you targeted the intended project (--project / MASTRA_PROJECT_ID) — you may be pointing at an undeployed project
- Check the Mastra Cloud dashboard that the project actually has environments
- If environments were deleted, redeploy to recreate them
Example fix
// before mastra env vars pull // Error: No environments found... // after mastra deploy && mastra env vars pull
Defensive patterns
Strategy: fallback
Validate before calling
const project = await resolveProject(args);
const environments = await fetchEnvironments(project.id);
if (environments.length === 0) {
console.warn(`Project ${project.slug} has no environments yet. Run \`mastra deploy\` first, or point --project at a deployed project.`);
process.exit(1);
} Type guard
function hasDeployedEnvironment(envs: unknown): envs is [{ id: string; name: string; slug: string }, ...unknown[]] {
return Array.isArray(envs) && envs.length > 0 &&
typeof (envs[0] as any)?.slug === 'string';
} Try / catch
try {
const vars = await pullEnvVars(args);
} catch (err) {
if (err instanceof Error && err.message.startsWith('No environments found')) {
console.error(`${err.message} (Check you targeted the right project with --project / MASTRA_PROJECT_ID.)`);
process.exitCode = 1;
return;
}
throw err;
} Prevention
- Deploy at least once (locally or via CI) before attempting env var pulls
- In CI, order pipelines so a deploy job precedes any env-pull job
- Verify project targeting when a project unexpectedly has no environments — you may be looking at the wrong one
- Avoid deleting the last environment of a project without redeploying
When it happens
Trigger: Calling `mastra env vars pull` (no explicit environment, or any call reaching pickEnvironment with environments.length === 0) against a project that has no deployments yet in Mastra Cloud.
Common situations: Newly created project never deployed; deploying happens only via CI while pulling vars locally; wrong project resolved (empty project vs. the one you deploy); environments were deleted in the dashboard.
Related errors
- 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
- .mastra/output/index.mjs not found — did the build succeed?
- Directory not found: ${dirArg}.${hint}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/b3334b6879da254a.
Report an issue: GitHub.