mastra-ai/mastra · error · Error
Multiple environments found (${slugs}). Specify one: mastra
Error message
Multiple environments found (${slugs}). Specify one: mastra env vars pull <environment> What it means
Thrown by `pickEnvironment` when no environment argument is supplied and the project has more than one environment, making the target ambiguous. The message lists all candidate slugs and tells you to pass one explicitly. Matching accepts environment id, name, or slug.
Source
Thrown at packages/cli/src/commands/env/vars.ts:39
.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 UI
* editor) merged with the project-scoped vars, with project values winning on
* conflict, matching the platform's deploy-time merge precedence. Managed
* vars (platform-injected secrets) are listed as comments, names only.
*
* The legacy `mastra server env pull` reads only the project scope; this is
* the unified-surface replacement that fixes UI-added vars silently missingView on GitHub (pinned to 75dd419e61)
Solutions
- Run with an explicit target: `mastra env vars pull <slug>` using one of the listed slugs (e.g. production or staging)
- Set the environment argument in your CI script so it's deterministic
- If you only need one environment, delete/consolidate unused environments in Mastra Cloud (if intended)
- Pipe the slug from a script: `mastra env vars pull $(mastra env list --slug production)` pattern or hardcode the slug
Example fix
// before mastra env vars pull // Multiple environments found (production, staging)... // after mastra env vars pull production
Defensive patterns
Strategy: validation
Validate before calling
const environments = await fetchEnvironments(project.id);
if (!envArg && environments.length > 1) {
throw new Error(`Pass an explicit environment. Available: ${environments.map(e => e.slug).join(', ')}`);
} Type guard
function isKnownEnvironment(envs: { id: string; name: string; slug: string }[], arg: string): boolean {
return envs.some(e => e.id === arg || e.name === arg || e.slug === arg);
} Try / catch
try {
const vars = await pullEnvVars({ environment: envArg });
} catch (err) {
if (err instanceof Error && err.message.startsWith('Multiple environments found')) {
const slugs = err.message.match(/\(([^)]+)\)/)?.[1]?.split(', ') ?? [];
console.error(`${err.message}\nPick one, e.g.: mastra env vars pull ${slugs[0] ?? '<slug>'}`);
process.exitCode = 1;
return;
}
throw err;
} Prevention
- Always pass an explicit environment slug in scripts and CI so they survive new environments being added
- Parse the slug list from the error message to build interactive prompts (e.g. @clack/prompts select)
- Standardize on known environment slugs (production, staging) across projects
- Periodically remove stale environments so ambiguity doesn't creep in
When it happens
Trigger: `mastra env vars pull` (without <environment>) against a project whose environments array has length > 1, e.g. both 'production' and 'staging' exist.
Common situations: Project promoted from single-dev to multi-environment setup (added staging); copy-pasted command from docs that assumed one environment; CI script written when the project had one environment, then a second was added.
Related errors
- Project ${project.name} has multiple environments (${slugs})
- Found ${projects.length} existing project(s) in this organiz
- Project not found: ${wanted}
- No project specified. Pass --project <name|slug|id>, set MAS
- No environments found for this project. Deploy first with `m
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/b7b43ca2b34c76c1.
Report an issue: GitHub.