{"record":{"id":"ffde2824476e0d14","repo":"handlebars-lang/handlebars.js","slug":"unable-to-output-multiple-templates-in-simple-mode","errorCode":null,"errorMessage":"Unable to output multiple templates in simple mode","messagePattern":"Unable to output multiple templates in simple mode","errorType":"exception","errorClass":"Handlebars.Exception","httpStatus":null,"severity":"error","filePath":"lib/precompiler.js","lineNumber":173,"sourceCode":"export async function cli(opts) {\n  if (opts.version) {\n    console.log(Handlebars.VERSION);\n    return;\n  }\n\n  if (!opts.templates.length && !opts.hasDirectory) {\n    throw new Handlebars.Exception(\n      'Must define at least one template or directory.'\n    );\n  }\n\n  if (opts.simple && opts.min) {\n    throw new Handlebars.Exception('Unable to minimize simple output');\n  }\n\n  const multiple = opts.templates.length !== 1 || opts.hasDirectory;\n  if (opts.simple && multiple) {\n    throw new Handlebars.Exception(\n      'Unable to output multiple templates in simple mode'\n    );\n  }\n\n  // Force simple mode if we have only one template and it's unnamed.\n  if (opts.templates.length === 1 && !opts.templates[0].name) {\n    opts.simple = true;\n  }\n\n  // Convert the known list into a hash\n  let known = {};\n  if (opts.known && !Array.isArray(opts.known)) {\n    opts.known = [opts.known];\n  }\n  if (opts.known) {\n    for (let i = 0, len = opts.known.length; i < len; i++) {\n      known[opts.known[i]] = true;\n    }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/handlebars-lang/handlebars.js/blob/13a7a679910d2adbfe7f6fad61ce8f98426b0378/lib/precompiler.js#L155-L191","documentation":"The precompiler CLI throws when --simple (-s) is used but more than one template (or a directory of templates) is provided. Simple mode emits exactly one bare template function with no registry, so it can only handle a single named template.","triggerScenarios":"Running `handlebars -s templates/a.hbs templates/b.hbs` or `handlebars -s templates/` (directory implies multiple).","commonSituations":"Pointing -s at a whole templates directory; glob expansion passing several files to a simple-mode compile; precompiled multiple files being concatenated later.","solutions":["Compile a single template file with -s, one output per template","Drop -s so multiple templates compile into the standard registry format","Run the CLI once per template with -s and separate -f outputs"],"exampleFix":"// before\nhandlebars -s src/templates/ -f dist/tpl.js\n\n// after\nhandlebars src/templates/ -f dist/tpl.js\n// or simple, one at a time\nhandlebars -s src/templates/home.hbs -f dist/home.js","handlingStrategy":"validation","validationCode":"const fileCount = (await glob(templatesGlob)).length;\nif (flags.simple && fileCount !== 1) {\n  throw new Error('--simple supports exactly one template; got ' + fileCount);\n}","typeGuard":null,"tryCatchPattern":"try {\n  execSync(cliCmd);\n} catch (e) {\n  if (/multiple templates in simple mode/.test(e.message)) {\n    // remove -s or compile one template at a time\n  } else throw e;\n}","preventionTips":["Only use -s for single-template builds; never point it at a directory","Loop over files invoking the CLI once per template when simple output is needed","Assert template file count in wrapper scripts before calling the CLI"],"tags":["handlebars","cli","precompiler","simple-mode","multiple-templates"],"backgroundTag":"incompatible-cli-options","analyzedSha":"13a7a679910d2adbfe7f6fad61ce8f98426b0378","analyzedAt":"2026-09-02T20:25:07.518Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}