yamadashy/repomix · error · RepomixError

Failed to compile template: ${error instanceof Error ? error

Error message

Failed to compile template: ${error instanceof Error ? error.message : 'Unknown error'}

What it means

After excluding the known string-limit failure, any other exception during Handlebars rendering is rethrown as 'Failed to compile template' with the original error preserved as `cause`. It indicates template compilation/execution itself failed rather than output size.

Source

Thrown at src/core/output/outputGenerate.ts:258

      if (processedFiles && processedFiles.length > 0) {
        const topFiles = processedFiles
          .sort((a, b) => b.content.length - a.content.length)
          .slice(0, 5)
          .map((f) => `  - ${f.path} (${(f.content.length / 1024 / 1024).toFixed(1)} MB)`)
          .join('\n');
        largeFilesInfo = `\n\nLargest files in this repository:\n${topFiles}`;
      }

      throw new RepomixError(
        `Output size exceeds JavaScript string limit. The repository contains files that are too large to process.
Please try:
  - Use --ignore to exclude large files (e.g., --ignore "docs/**" or --ignore "*.html")
  - Use --include to process only specific files
  - Process smaller portions of the repository at a time${largeFilesInfo}`,
        { cause: error },
      );
    }
    throw new RepomixError(
      `Failed to compile template: ${error instanceof Error ? error.message : 'Unknown error'}`,
      error instanceof Error ? { cause: error } : undefined,
    );
  }
};

export const generateOutput = async (
  rootDirs: string[],
  config: RepomixConfigMerged,
  processedFiles: ProcessedFile[],
  allFilePaths: string[],
  gitDiffResult: GitDiffResult | undefined = undefined,
  gitLogResult: GitLogResult | undefined = undefined,
  filePathsByRoot?: FilesByRoot[],
  emptyDirPaths?: string[],
  deps = {
    buildOutputGeneratorContext,
    generateHandlebarOutput,

View on GitHub (pinned to f465ad9093)

Solutions

  1. Inspect `error.cause` for the real Handlebars/template error.
  2. Reinstall/upgrade repomix to restore intact template assets.
  3. Remove any local template overrides or custom Handlebars helpers.
  4. If it persists, isolate with a small repo and --style plain to narrow the failing template.

Example fix

// before
customHelper registered as undefined -> template throws at render
// after
Handlebars.registerHelper('myHelper', myHelperFn); // ensure defined before generateOutput
Defensive patterns

Strategy: try-catch

Validate before calling

// verify template registration before rendering
if (typeof Handlebars.helpers?.each !== 'function') {
  throw new Error('Handlebars builtin helpers missing; check handlebars installation');
}

Type guard

null

Try / catch

try {
  const out = await generateOutput(config, ctx);
} catch (e) {
  if (e instanceof RepomixError && e.message.startsWith('Failed to compile template')) {
    console.error('Template error:', (e as { cause?: Error }).cause?.message);
  }
}

Prevention

When it happens

Trigger: generateHandlebarOutput catches an error whose message does not match the string-limit case — e.g. a Handlebars syntax/runtime error, missing helper, or an error thrown from within template processing — and wraps it.

Common situations: Corrupted or customized templates; Handlebars version incompatibility; bugs in custom styling integrations; unexpected data shapes hitting template helpers (e.g. undefined accessed by a strict helper).

Related errors


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/9383640fc29c3c7f. Report an issue: GitHub.