{"record":{"id":"6b75622bd5b6b94e","repo":"mastra-ai/mastra","slug":"no-env-file-found-for-deploy-add-a-env-or-env-6b7562","errorCode":null,"errorMessage":"No env file found for deploy. Add a .env or .env.* file before deploying.","messagePattern":"No env file found for deploy\\. Add a \\.env or \\.env\\.\\* file before deploying\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/studio/deploy.ts","lineNumber":154,"sourceCode":"  projectDir: string,\n  options: { autoAccept?: boolean; envFile?: string } = {},\n): Promise<Record<string, string>> {\n  // When an explicit env file is provided, trust the user — read it directly.\n  if (options.envFile) {\n    const filePath = join(projectDir, options.envFile);\n    try {\n      await access(filePath);\n    } catch {\n      throw new Error(`Env file not found: ${options.envFile}`);\n    }\n    p.log.step(`Using env file: ${options.envFile}`);\n    return parseEnvFile(await readFile(filePath, 'utf-8'));\n  }\n\n  const availableDeployEnvFiles = await getDeployEnvFiles(projectDir);\n\n  if (availableDeployEnvFiles.length === 0) {\n    throw new Error('No env file found for deploy. Add a .env or .env.* file before deploying.');\n  }\n\n  let selectedEnvFile: string;\n\n  if (availableDeployEnvFiles.length === 1) {\n    selectedEnvFile = availableDeployEnvFiles[0]!;\n  } else if (options.autoAccept) {\n    throw new Error(\n      `Multiple env files found: ${availableDeployEnvFiles.join(', ')}. Use --env-file to specify which one to deploy.`,\n    );\n  } else {\n    const defaultFile =\n      availableDeployEnvFiles.find(envFile => envFile === '.env.production') ?? availableDeployEnvFiles[0]!;\n\n    const selected = await p.select({\n      message: 'Choose env file to deploy',\n      options: availableDeployEnvFiles.map(envFile => ({ value: envFile, label: envFile })),\n      initialValue: defaultFile,","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/studio/deploy.ts#L136-L172","documentation":"Thrown by readEnvVars when no explicit env file was given and the deploy env-file discovery (getDeployEnvFiles, matching `.env` and `.env.*` in the project directory) found zero candidates. Studio deploys require environment variables, so the CLI refuses to proceed and asks the user to add an env file before deploying.","triggerScenarios":"Running `mastra studio deploy` in a project directory containing no `.env` or `.env.*` files (and no --env-file option), or where the files are located in a subdirectory other than the project root the CLI scans.","commonSituations":"Fresh project where env vars live only in the shell or CI secrets but never in a `.env` file; gitignored env files absent on a fresh clone; deploying from a directory copy without env files; `.env` stored one level up from the project root.","solutions":["Create a `.env` file at the project root with the required variables, then re-run the deploy.","Or pass an existing file explicitly: `mastra studio deploy --env-file path/to/.env`.","Check the files are at the project root the CLI is run from — `.env` in a parent or child directory won't be found.","In CI, write secrets into a `.env` file in a pre-deploy step."],"exampleFix":"// before\nmastra studio deploy   # no .env anywhere\n// after\ncat > .env <<'EOF'\nOPENAI_API_KEY=sk-...\nEOF\nmastra studio deploy","handlingStrategy":"validation","validationCode":"import { readdirSync } from 'node:fs';\nconst hasEnv = readdirSync(projectDir).some(f => f === '.env' || f.startsWith('.env.'));\nif (!hasEnv && !options.envFile) {\n  console.error(`No .env/.env.* in ${projectDir}; create one or pass --env-file before deploying.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runStudioDeploy(options);\n} catch (err) {\n  if ((err as Error).message.includes('No env file found for deploy')) {\n    console.error('Create a .env at the project root or pass --env-file <path>.');\n    return;\n  }\n  throw err;\n}","preventionTips":["Maintain a committed `.env.example` and copy it to `.env` during setup.","In CI, write required secrets into a `.env` file before `mastra studio deploy`.","Place env files at the project root the CLI runs from — parent/child directories are not scanned.","Alternatively pass --env-file explicitly to skip discovery."],"tags":["cli","env","deploy","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}