{"record":{"id":"a2f75d838da52c92","repo":"mastra-ai/mastra","slug":"deployer-bundler-bundle-stage-failed","errorCode":"DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED","errorMessage":"Failed during bundler bundle stage: ${message}","messagePattern":"Failed during bundler bundle stage: (.+?)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/deployer/src/bundler/index.ts","lineNumber":813,"sourceCode":"      if (Object.keys(transitiveWorkspaceDependencies.resolutions).length === 0) {\n        this.logger.info('Generating package-lock.json for deploy');\n        await this.generateNpmLockfile(join(outputDirectory, this.outputDir));\n        this.logger.info('Done generating package-lock.json');\n      } else {\n        this.logger.warn(\n          'Skipping package-lock.json generation because the output contains packed workspace dependencies',\n        );\n      }\n    } catch (error) {\n      if (\n        error instanceof MastraError &&\n        (error.id === 'DEPLOYER_BUNDLER_FACTORY_UI_MISSING' || error.id === 'DEPLOYER_PNPM_IGNORED_BUILDS')\n      ) {\n        throw error;\n      }\n\n      const message = error instanceof Error ? error.message : String(error);\n      throw new MastraError(\n        {\n          id: 'DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED',\n          text: `Failed during bundler bundle stage: ${message}`,\n          domain: ErrorDomain.DEPLOYER,\n          category: ErrorCategory.SYSTEM,\n        },\n        error,\n      );\n    }\n  }\n\n  async lint(_entryFile: string, _outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n    const toolsInputOptions = await this.listToolsInputOptions(toolsPaths);\n    const toolsLength = Object.keys(toolsInputOptions).length;\n    if (toolsLength > 0) {\n      this.logger.info('Found tools', { count: toolsLength });\n    }\n  }","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/deployer/src/bundler/index.ts#L795-L831","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (broken import causes bundle failure)\nimport { agent } from './agnet'; // typo\n// after\nimport { agent } from './agent';","handlingStrategy":"try-catch","validationCode":"npx tsc --noEmit && node -e \"require('fs').accessSync('./mastra')\" # surface compile errors before deploy","typeGuard":null,"tryCatchPattern":"try {\n  await deploy();\n} catch (e) {\n  if (e?.id === 'DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED') {\n    console.error('Bundler failed:', e.message.replace('Failed during bundler bundle stage: ', ''));\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["deployer","bundler","build"],"backgroundTag":"bundler-bundle-stage-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}