mastra-ai/mastra · error · Error
Project ${project.name} has no environments. Create one with
Error message
Project ${project.name} has no environments. Create one with: mastra env create <name> What it means
resolveDefaultEnvironment() is used when no environment argument is given (e.g. `mastra env db create` without <env> or --shared); if the project has zero environments there is no default to resolve, so it throws with instructions to create one first.
Source
Thrown at packages/cli/src/commands/db/db.ts:355
/**
* When the user runs `mastra env db create` without an environment argument
* and without --shared, pick the environment to scope the new database to:
* - exactly one environment → use it
* - multiple environments + interactive TTY → prompt with a picker
* - multiple environments + non-interactive → fail with a clear message
* - zero environments → fail (nothing to attach to)
*/
export async function resolveDefaultEnvironment(
token: string,
orgId: string,
project: Project,
opts: { json?: boolean } = {},
): Promise<Environment> {
const environments = await fetchEnvironments(token, orgId, project.id);
if (environments.length === 0) {
throw new Error(`Project ${project.name} has no environments. Create one with: mastra env create <name>`);
}
if (environments.length === 1) {
return environments[0]!;
}
if (opts.json || !isInteractive()) {
const slugs = environments.map(e => e.slug).join(', ');
throw new Error(
`Project ${project.name} has multiple environments (${slugs}). Pass an environment name (e.g. ` +
`\`mastra env db create <env> --kind ...\`) or use --shared to attach a project-scoped database.`,
);
}
// Prefer production as the pre-selected option when it exists.
const preferred = environments.find(e => e.type === 'production') ?? environments[0]!;
const selected = await p.select({View on GitHub (pinned to 75dd419e61)
Solutions
- Create an environment: `mastra env create <name>` (e.g. production), then re-run the db command.
- Verify you're targeting the intended project with `--project <name>`.
- Use `mastra env list` to confirm the environment was created before retrying.
Example fix
// before mastra env db create --kind turso # project has no environments // after mastra env create production mastra env db create production --kind turso
Defensive patterns
Strategy: validation
Validate before calling
const envs = await listEnvironments();
if (envs.length === 0) {
throw new Error('Create an environment first: mastra env create <name>');
} Try / catch
try {
await dbCreate();
} catch (e) {
if (/has no environments/.test((e as Error).message)) {
console.error('Provision an environment with `mastra env create <name>` before creating databases.');
}
} Prevention
- Provision at least one environment as part of project onboarding.
- In automation, check `mastra env list` is non-empty before db commands.
- Confirm --project points at the intended, provisioned project.
When it happens
Trigger: Running a db command that needs an implicit environment on a freshly created project that has never had `mastra env create` run.
Common situations: New Mastra Cloud project onboarding, automation that skipped environment provisioning, or operating against the wrong project which happens to have no environments.
Related errors
- Environment not found: ${envArg}. List environments with: ma
- Database not found: ${dbArg}. List databases with: mastra en
- Project ${project.name} has multiple environments (${slugs})
- MASTRA_ORG_ID and MASTRA_PROJECT_ID are required when MASTRA
- @mastra/livekit: no fetch implementation available; pass `fe
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/eff81f1afb9423bd.
Report an issue: GitHub.