{"record":{"id":"7fcdd12341b2b68b","repo":"mastra-ai/mastra","slug":"mastra-does-not-provide-an-export-named-mastra","errorCode":null,"errorMessage":"#mastra does not provide an export named 'mastra'","messagePattern":"#mastra does not provide an export named 'mastra'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/cli/src/commands/experiment/ExperimentBundler.ts","lineNumber":151,"sourceCode":"    };\n    await writeFile(join(outputDirectory, 'experiment-worker-manifest.json'), JSON.stringify(manifest, null, 2));\n  }\n\n  protected getEntry(): string {\n    const runtimePath = resolveRuntimePath();\n    return `\nimport { readFile } from 'node:fs/promises';\nimport { runExperimentWorker } from ${JSON.stringify(runtimePath)};\n\nconsole.log = (...args) => console.error(...args);\nconsole.info = (...args) => console.error(...args);\nconsole.debug = (...args) => console.error(...args);\nconst [{ runExperiment }, mastraModule] = await Promise.all([\n  import('@mastra/core/datasets'),\n  import('#mastra'),\n]);\nconst { mastra } = mastraModule;\nif (!mastra) throw new Error(\"#mastra does not provide an export named 'mastra'\");\nconst artifactManifest = JSON.parse(\n  await readFile(new URL('./experiment-worker-manifest.json', import.meta.url), 'utf8'),\n);\nconst exitCode = await runExperimentWorker({\n  mastra,\n  runExperiment,\n  build: {\n    buildId: artifactManifest.build.buildId,\n    protocolVersion: artifactManifest.protocol.versions[0],\n    datasetCanonicalizationVersion: artifactManifest.protocol.datasetCanonicalizationVersion,\n  },\n});\nawait Promise.race([\n  new Promise(resolve => process.stdout.end(resolve)),\n  new Promise(resolve => setTimeout(resolve, 5_000)),\n]);\nprocess.exit(exitCode);\n`;","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/experiment/ExperimentBundler.ts#L133-L169","documentation":"The experiment worker entry point imports the user's Mastra instance via the `#mastra` package specifier and destructures the `mastra` export. If the resolved module exports nothing named `mastra` (falsy), the worker aborts at startup with this error. The experiment runner requires a single canonical `mastra` export to enumerate agents/workflows for the run.","triggerScenarios":"The bundled user source (the `#mastra` import target, e.g. src/mastra/index.ts) does not export a `mastra` binding, exports it under a different name, or conditionally exports undefined (e.g. from a branch that failed to initialize).","commonSituations":"Index file exports `export const mastra = new Mastra()` missing after a refactor; only default export present; export renamed to `mastraInstance`; tree-shaking or an accidental re-export shadowing `mastra`; partial file where `new Mastra(...)` is commented out.","solutions":["Ensure src/mastra/index.ts contains `export const mastra = new Mastra({...})` (named export, exactly `mastra`).","Check for typos or renames like `export const m = ...` and fix the export name.","Remove conditional branches that can leave `mastra` undefined; the export must always be defined.","Rebuild the experiment worker after fixing, then re-run."],"exampleFix":"// before (src/mastra/index.ts)\nexport const mastraInstance = new Mastra({ agents: {} });\n// after\nexport const mastra = new Mastra({ agents: {} });","handlingStrategy":"type-guard","validationCode":"// in src/mastra/index.ts, verify before shipping:\nconst mod = await import('./src/mastra/index.js');\nif (!('mastra' in mod) || !mod.mastra) throw new Error('src/mastra/index.ts must export a defined `mastra`');","typeGuard":"function hasMastraExport(mod: unknown): mod is { mastra: NonNullable<unknown> } {\n  return typeof mod === 'object' && mod !== null && 'mastra' in mod && (mod as any).mastra != null;\n}","tryCatchPattern":"try {\n  await runExperimentWorker({ mastra, runExperiment, build });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"export named 'mastra'\")) {\n    console.error('Add `export const mastra = new Mastra({...})` to your mastra index');\n  } else throw e;\n}","preventionTips":["Always `export const mastra = new Mastra({...})` as a named export in src/mastra/index.ts","Never rename or alias the mastra export during refactors","Avoid conditional/undefined exports in the mastra index","Add a smoke test importing your mastra entry and asserting the export exists"],"tags":["runtime","module-exports","experiment-worker"],"backgroundTag":"missing-named-export","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}