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

  1. Read the inner message after the colon — fix the underlying bundler/compiler error it reports.
  2. Run `mastra dev` or a direct TypeScript check (`tsc --noEmit`) to surface syntax/type errors in your mastra directory.
  3. Verify all imports in your Mastra files resolve (packages installed, correct relative paths).
  4. 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

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


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/a2f75d838da52c92. Report an issue: GitHub.