yamadashy/repomix · error · RepomixError

Output size exceeds JavaScript string limit. The repository

Error message

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}

What it means

The fully rendered output string exceeded V8's maximum string length (~512MB/1GB). Repomix catches this during Handlebars rendering and throws this actionable error, optionally appending the largest files (with sizes) to help you shrink the pack.

Source

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

  renderContext: RenderContext,
  processedFiles?: ProcessedFile[],
): Promise<string> => {
  try {
    const compiledTemplate = getCompiledTemplate(config.output.style);
    return `${compiledTemplate(renderContext).trim()}\n`;
  } catch (error) {
    if (error instanceof RangeError && error.message === 'Invalid string length') {
      let largeFilesInfo = '';
      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,

View on GitHub (pinned to f465ad9093)

Solutions

  1. Add --ignore patterns for large/generated files (e.g. --ignore "docs/**" or --ignore "*.html").
  2. Use --include to pack only the directories you need.
  3. Split the run: pack subdirectories separately.
  4. Identify the files listed under 'Largest files in this repository' and exclude or trim them.

Example fix

// before
repomix  # huge monorepo, exceeds string limit
// after
repomix --ignore "**/dist/**,**/docs/**,**/*.min.js"
Defensive patterns

Strategy: validation

Validate before calling

const total = files.reduce((n, f) => n + f.content.length, 0);
const MAX = 500 * 1024 * 1024; // stay under JS string limit
if (total > MAX) {
  const worst = [...files].sort((a, b) => b.content.length - a.content.length).slice(0, 5);
  throw new Error(`Output ~${(total / 1e6).toFixed(0)}MB too large; exclude: ${worst.map(f => f.path).join(', ')}`);
}

Type guard

null

Try / catch

try {
  await repomixCli.run(args);
} catch (e) {
  if (e instanceof RepomixError && e.message.includes('Output size exceeds JavaScript string limit')) {
    // parse the 'Largest files' section and add matching --ignore patterns, then retry
  }
}

Prevention

When it happens

Trigger: generateHandlebarOutput renders a repository whose combined file contents exceed the JS string limit; the caught RangeError 'Invalid string length' is replaced by this message including largeFilesInfo when the largest files can be computed.

Common situations: Packing monorepos or repos with huge generated assets (docs builds, minified bundles, lockfiles); running with no ignore patterns on very large codebases.

Related errors


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