{"record":{"id":"17b4886e4e124966","repo":"mastra-ai/mastra","slug":"mastra-output-index-mjs-not-found-did-the-build-17b488","errorCode":null,"errorMessage":".mastra/output/index.mjs not found — did the build succeed?","messagePattern":"\\.mastra/output/index\\.mjs not found — did the build succeed\\?","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/server/deploy.ts","lineNumber":482,"sourceCode":"    }\n    p.log.step('Skipping build (--skip-build)');\n  } else if (staleness.isStale) {\n    // Build is stale or doesn't exist — rebuild\n    if (staleness.reason === 'hash-mismatch') {\n      p.log.step('Source files changed, rebuilding...');\n    }\n    await runBuild(targetDir, { debug: opts.debug });\n  } else {\n    // Build is up-to-date — skip rebuild\n    p.log.step('Build is up-to-date, skipping rebuild');\n  }\n\n  // Verify build output exists\n  const outputEntry = join(targetDir, '.mastra', 'output', 'index.mjs');\n  try {\n    await access(outputEntry);\n  } catch {\n    throw new Error('.mastra/output/index.mjs not found — did the build succeed?');\n  }\n\n  // If the user didn't pass --env-file and no ambient .env* file exists,\n  // skip the local env-var upload entirely and let the platform use the\n  // env vars stored on the project. The server-side deploy handler merges\n  // request envVars over the stored vars, so an empty (absent) envVars\n  // payload cleanly falls back to what's already stored.\n  let envVars: Record<string, string> = {};\n  const hasEnvFile = opts.envFile ? true : (await getDeployEnvFiles(targetDir)).length > 0;\n  if (hasEnvFile) {\n    envVars = await readEnvVars(targetDir, { autoAccept, envFile: opts.envFile });\n  }\n  const envCount = Object.keys(envVars).length;\n  if (envCount > 0) {\n    p.log.step(`Found ${envCount} env var(s)`);\n  } else if (hasEnvFile) {\n    p.log.step('No env vars found in selected env file');\n  } else {","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/server/deploy.ts#L464-L500","documentation":"After (optionally) building, runServerDeploy verifies the build entrypoint .mastra/output/index.mjs exists via fs access. If the file is absent it throws — the CLI refuses to package and upload a deploy that has no build artifact, since the platform build would have nothing to run.","triggerScenarios":"Deploy ran with a build that failed or produced no output; build wrote output to a different directory; `mastra build` was never run in this project; --skipBuild was passed in a directory with no prior successful build; a custom build config changed the output path away from .mastra/output.","commonSituations":"Build step failed earlier (TS errors, missing deps) but the deploy script continued due to `|| true` or ignore-errors CI settings; wrong working directory (deploying from repo root of a monorepo where build outputs live in packages/*); mastraConfig output customized.","solutions":["Run `mastra build` in the deploy directory and check it completes without errors, then confirm .mastra/output/index.mjs exists","Fix the underlying build failure (inspect `mastra build` output for TS/import errors)","Remove --skipBuild, or run a build before deploying with --skipBuild","If output path is customized, ensure the entry lands at .mastra/output/index.mjs or revert the custom output config","Run the deploy from the correct package directory in monorepos"],"exampleFix":"// before (package.json script)\n\"deploy\": \"mastra build || true && mastra server deploy --skipBuild\"\n// after\n\"deploy\": \"mastra build && mastra server deploy\"","handlingStrategy":"validation","validationCode":"import { access } from 'node:fs/promises';\n// Run before deploying\ntry {\n  await access('.mastra/output/index.mjs');\n} catch {\n  throw new Error('Build output missing — run `mastra build` first.');\n}","typeGuard":"function isStatFile(stat: { isFile(): boolean } | undefined): boolean {\n  return Boolean(stat?.isFile());\n}","tryCatchPattern":"try {\n  await deploy();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('not found — did the build succeed?')) {\n    console.error('Run `mastra build` and confirm .mastra/output/index.mjs exists.');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Chain build and deploy with && so a failed build blocks deploy","Never use `|| true` around build steps in CI","Verify .mastra/output/index.mjs exists after customizing build output paths","Run deploys from the package directory that owns the .mastra output"],"tags":["cli","build","filesystem","artifact"],"backgroundTag":"build-output-missing","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}