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 UI

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Deploy the project first: run `mastra deploy` (or trigger your CI deploy pipeline), then retry the pull
  2. Verify you targeted the intended project (--project / MASTRA_PROJECT_ID) — you may be pointing at an undeployed project
  3. Check the Mastra Cloud dashboard that the project actually has environments
  4. 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

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


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/b3334b6879da254a. Report an issue: GitHub.