{"record":{"id":"9383640fc29c3c7f","repo":"yamadashy/repomix","slug":"failed-to-compile-template-error-instanceof-err","errorCode":null,"errorMessage":"Failed to compile template: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Failed to compile template: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/output/outputGenerate.ts","lineNumber":258,"sourceCode":"      if (processedFiles && processedFiles.length > 0) {\n        const topFiles = processedFiles\n          .sort((a, b) => b.content.length - a.content.length)\n          .slice(0, 5)\n          .map((f) => `  - ${f.path} (${(f.content.length / 1024 / 1024).toFixed(1)} MB)`)\n          .join('\\n');\n        largeFilesInfo = `\\n\\nLargest files in this repository:\\n${topFiles}`;\n      }\n\n      throw new RepomixError(\n        `Output size exceeds JavaScript string limit. The repository contains files that are too large to process.\nPlease try:\n  - Use --ignore to exclude large files (e.g., --ignore \"docs/**\" or --ignore \"*.html\")\n  - Use --include to process only specific files\n  - Process smaller portions of the repository at a time${largeFilesInfo}`,\n        { cause: error },\n      );\n    }\n    throw new RepomixError(\n      `Failed to compile template: ${error instanceof Error ? error.message : 'Unknown error'}`,\n      error instanceof Error ? { cause: error } : undefined,\n    );\n  }\n};\n\nexport const generateOutput = async (\n  rootDirs: string[],\n  config: RepomixConfigMerged,\n  processedFiles: ProcessedFile[],\n  allFilePaths: string[],\n  gitDiffResult: GitDiffResult | undefined = undefined,\n  gitLogResult: GitLogResult | undefined = undefined,\n  filePathsByRoot?: FilesByRoot[],\n  emptyDirPaths?: string[],\n  deps = {\n    buildOutputGeneratorContext,\n    generateHandlebarOutput,","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/output/outputGenerate.ts#L240-L276","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Inspect `error.cause` for the real Handlebars/template error.","Reinstall/upgrade repomix to restore intact template assets.","Remove any local template overrides or custom Handlebars helpers.","If it persists, isolate with a small repo and --style plain to narrow the failing template."],"exampleFix":"// before\ncustomHelper registered as undefined -> template throws at render\n// after\nHandlebars.registerHelper('myHelper', myHelperFn); // ensure defined before generateOutput","handlingStrategy":"try-catch","validationCode":"// verify template registration before rendering\nif (typeof Handlebars.helpers?.each !== 'function') {\n  throw new Error('Handlebars builtin helpers missing; check handlebars installation');\n}","typeGuard":"null","tryCatchPattern":"try {\n  const out = await generateOutput(config, ctx);\n} catch (e) {\n  if (e instanceof RepomixError && e.message.startsWith('Failed to compile template')) {\n    console.error('Template error:', (e as { cause?: Error }).cause?.message);\n  }\n}","preventionTips":["Do not modify bundled templates; keep repomix installs intact.","Pin a compatible handlebars version in custom integrations.","Reproduce with --style plain and a tiny repo to isolate the failing template.","Check error.cause for the exact Handlebars message before filing bugs."],"tags":["output","template","handlebars"],"backgroundTag":"template-compile-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}