mastra-ai/mastra · error

mastra-wrapper plugin did not return code, there is likely a

Error message

mastra-wrapper plugin did not return code, there is likely a bug in the plugin.

What it means

During deployment the Cloudflare deployer transforms your entry code with Babel using the `mastraInstanceWrapperBabel` plugin. If Babel returns a result with no `code`, the transform produced no output, and the deployer aborts with this internal-bug diagnostic. It should never happen in a healthy setup.

Source

Thrown at deployers/cloudflare/src/plugins/mastra-instance-wrapper.ts:21

import { mastraInstanceWrapper as mastraInstanceWrapperBabel } from '../babel/mastra-instance-wrapper';

export function mastraInstanceWrapper(mastraEntryFile: string): Plugin {
  return {
    name: 'mastra-wrapper',
    transform(code, id) {
      if (id !== mastraEntryFile) {
        return null;
      }

      const result = transformSync(code, {
        filename: id,
        babelrc: false,
        configFile: false,
        plugins: [mastraInstanceWrapperBabel],
      });

      if (!result?.code) {
        throw new Error('mastra-wrapper plugin did not return code, there is likely a bug in the plugin.');
      }

      return {
        code: result.code,
        map: result?.map as SourceMapInput | undefined,
      };
    },
  };
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Upgrade @mastra/deployers (and the mastra suite) to the latest patch where the plugin bug may be fixed.
  2. Check for duplicate/mismatched @babel/core versions (`pnpm why @babel/core`) and dedupe so the plugin runs against the Babel core it was built for.
  3. Run the same Babel transform manually on the entry file to expose any parse failure; fix the offending syntax.
  4. Pin a known-good previous deployer version as a workaround and file an upstream issue.

Example fix

// before
const result = transform(code, { babelrc: false, configFile: false, plugins: [mastraInstanceWrapperBabel] });
// after (diagnose which input/plugin fails)
const result = transform(code, { babelrc: false, configFile: false, plugins: [mastraInstanceWrapperBabel], filename: 'mastra-entry.ts' });
if (!result?.code) throw new Error(`transform returned no code; @babel/core version: ${BABEL_VERSION}`);
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the entry file parses before trusting the plugin's output
import { parse } from '@babel/core';
function canParse(code: string): boolean {
  try { parse(code, { babelrc: false, configFile: false, sourceType: 'module' }); return true; }
  catch { return false; }
}

Type guard

function hasTransformCode(r: unknown): r is { code: string; map?: unknown } {
  return typeof r === 'object' && r !== null && typeof (r as any).code === 'string' && (r as any).code.length > 0;
}

Try / catch

try {
  const out = transformer.transform(code);
} catch (err) {
  if (err instanceof Error && err.message.includes('mastra-wrapper plugin did not return code')) {
    console.error('Babel plugin produced no output. Check @babel/core version match and entry-file syntax.', err);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `transform()` when the Babel transform with `mastraInstanceWrapperBabel` returns null/undefined or a result without a `code` property (parse failure, incompatible Babel core, or a genuine plugin bug).

Common situations: Version mismatch between @mastra/deployers and @babel/core in the consumer's dependency tree; entry-file syntax the Babel config cannot parse; duplicated/corrupted Babel installations; upstream plugin regression.

Related errors


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