mastra-ai/mastra · error · MastraError
DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED
DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED
Error message
Failed during bundler bundle stage: ${message} What it means
The deployer's bundler wraps any failure thrown during the `bundle()` stage of the build pipeline in a MastraError with id DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED, preserving the underlying message. It re-throws known, already-annotated errors (DEPLOYER_BUNDLER_FACTORY_UI_MISSING, DEPLOYER_PNPM_IGNORED_BUILDS) unchanged so their specific guidance survives. This is a generic wrapper meaning the actual cause is the inner message.
Source
Thrown at packages/deployer/src/bundler/index.ts:813
if (Object.keys(transitiveWorkspaceDependencies.resolutions).length === 0) {
this.logger.info('Generating package-lock.json for deploy');
await this.generateNpmLockfile(join(outputDirectory, this.outputDir));
this.logger.info('Done generating package-lock.json');
} else {
this.logger.warn(
'Skipping package-lock.json generation because the output contains packed workspace dependencies',
);
}
} catch (error) {
if (
error instanceof MastraError &&
(error.id === 'DEPLOYER_BUNDLER_FACTORY_UI_MISSING' || error.id === 'DEPLOYER_PNPM_IGNORED_BUILDS')
) {
throw error;
}
const message = error instanceof Error ? error.message : String(error);
throw new MastraError(
{
id: 'DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED',
text: `Failed during bundler bundle stage: ${message}`,
domain: ErrorDomain.DEPLOYER,
category: ErrorCategory.SYSTEM,
},
error,
);
}
}
async lint(_entryFile: string, _outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {
const toolsInputOptions = await this.listToolsInputOptions(toolsPaths);
const toolsLength = Object.keys(toolsInputOptions).length;
if (toolsLength > 0) {
this.logger.info('Found tools', { count: toolsLength });
}
}View on GitHub (pinned to 75dd419e61)
Solutions
- Read the inner message after the colon — fix the underlying bundler/compiler error it reports.
- Run `mastra dev` or a direct TypeScript check (`tsc --noEmit`) to surface syntax/type errors in your mastra directory.
- Verify all imports in your Mastra files resolve (packages installed, correct relative paths).
- If the inner message is about pnpm blocked builds or a missing UI factory, look up those specific error ids for targeted fixes.
Example fix
// before (broken import causes bundle failure)
import { agent } from './agnet'; // typo
// after
import { agent } from './agent'; Defensive patterns
Strategy: try-catch
Validate before calling
npx tsc --noEmit && node -e "require('fs').accessSync('./mastra')" # surface compile errors before deploy Try / catch
try {
await deploy();
} catch (e) {
if (e?.id === 'DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED') {
console.error('Bundler failed:', e.message.replace('Failed during bundler bundle stage: ', ''));
}
throw e;
} Prevention
- Run TypeScript/lint checks locally before deploying
- Keep imports in mastra/ resolvable and dependency versions in sync
- Read the inner message — the wrapper id is generic, the cause is specific
When it happens
Trigger: Any unclassified Error thrown inside bundler.bundle() — e.g. esbuild/rollup compile failures, syntax errors in user Mastra files, unresolved imports, plugin failures — as long as the error's id is not DEPLOYER_BUNDLER_FACTORY_UI_MISSING or DEPLOYER_PNPM_IGNORED_BUILDS.
Common situations: TypeScript syntax errors in mastra/ files, importing a module that isn't installed, bad path aliases, bundler-native errors from esbuild or a custom bundler, out-of-memory during bundling on large projects.
Related errors
- Failed to copy studio assets from "${studioSource}" to "${st
- Missing required file, checked the following paths: ${files.
- FAIL_BUILD_SCRIPT
- FAIL_BUILD_COMMAND
- mastra-wrapper plugin did not return code, there is likely a
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/a2f75d838da52c92.
Report an issue: GitHub.