{"record":{"id":"b3334b6879da254a","repo":"mastra-ai/mastra","slug":"no-environments-found-for-this-project-deploy-fir","errorCode":null,"errorMessage":"No environments found for this project. Deploy first with `mastra deploy`.","messagePattern":"No environments found for this project\\. Deploy first with `mastra deploy`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/env/vars.ts","lineNumber":33,"sourceCode":"  const vars = env.command('vars').description(\"Manage an environment's variables\");\n\n  vars\n    .command('pull')\n    .description('Pull the merged env vars (environment + project scope) into a local env file')\n    .argument('[environment]', 'Environment name, slug, or ID (optional when the project has exactly one)')\n    .option('--project <project>', 'Project name, slug, or ID (default: linked project)')\n    .option('-o, --output <file>', 'File to write (default: .env)')\n    .option('-f, --force', 'Overwrite an existing output file')\n    .action(wrapAction(envVarsPullAction));\n}\n\nfunction isAlreadyExistsError(error: unknown): boolean {\n  return typeof error === 'object' && error !== null && 'code' in error && error.code === 'EEXIST';\n}\n\nfunction pickEnvironment(environments: Environment[], envArg: string | undefined): Environment {\n  if (environments.length === 0) {\n    throw new Error('No environments found for this project. Deploy first with `mastra deploy`.');\n  }\n\n  if (!envArg) {\n    if (environments.length === 1) return environments[0]!;\n    const slugs = environments.map(e => e.slug).join(', ');\n    throw new Error(`Multiple environments found (${slugs}). Specify one: mastra env vars pull <environment>`);\n  }\n\n  const env = environments.find(e => e.id === envArg || e.name === envArg || e.slug === envArg);\n  if (!env) {\n    throw new Error(`Environment not found: ${envArg}`);\n  }\n  return env;\n}\n\n/**\n * Pull the full set of env vars that a deploy of the target environment\n * actually runs with — the environment row's vars (e.g. added via the UI","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/env/vars.ts#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nmastra env vars pull   // Error: No environments found...\n// after\nmastra deploy && mastra env vars pull","handlingStrategy":"fallback","validationCode":"const project = await resolveProject(args);\nconst environments = await fetchEnvironments(project.id);\nif (environments.length === 0) {\n  console.warn(`Project ${project.slug} has no environments yet. Run \\`mastra deploy\\` first, or point --project at a deployed project.`);\n  process.exit(1);\n}","typeGuard":"function hasDeployedEnvironment(envs: unknown): envs is [{ id: string; name: string; slug: string }, ...unknown[]] {\n  return Array.isArray(envs) && envs.length > 0 &&\n    typeof (envs[0] as any)?.slug === 'string';\n}","tryCatchPattern":"try {\n  const vars = await pullEnvVars(args);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('No environments found')) {\n    console.error(`${err.message} (Check you targeted the right project with --project / MASTRA_PROJECT_ID.)`);\n    process.exitCode = 1;\n    return;\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["cli","mastra-cloud","deploy","empty-state"],"backgroundTag":"no-environments-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}