{"record":{"id":"d58a996b2e8d1a9f","repo":"handlebars-lang/handlebars.js","slug":"must-define-at-least-one-template-or-directory","errorCode":null,"errorMessage":"Must define at least one template or directory.","messagePattern":"Must define at least one template or directory\\.","errorType":"exception","errorClass":"Handlebars.Exception","httpStatus":null,"severity":"error","filePath":"lib/precompiler.js","lineNumber":162,"sourceCode":"    },\n    function (err) {\n      if (err) {\n        callback(err);\n      } else {\n        callback(undefined, ret);\n      }\n    }\n  );\n}\n\nexport 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;","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/handlebars-lang/handlebars.js/blob/13a7a679910d2adbfe7f6fad61ce8f98426b0378/lib/precompiler.js#L144-L180","documentation":"The handlebars precompiler CLI throws when neither template file arguments nor a directory (-d flag or directory arguments) is supplied — there is nothing to compile. opts.templates is empty and opts.hasDirectory is false.","triggerScenarios":"Running `handlebars` with no arguments, or with only flags like -f out.js but no template paths/directories.","commonSituations":"NPM script misconfigured (missing glob/path argument); CI invoking the CLI with an empty variable (e.g. $FILES unexpanded); wrong working directory where glob matches nothing is a related variant.","solutions":["Pass template paths: handlebars templates/ -f compiled.js","Fix the npm script so the glob/path arguments are actually expanded and non-empty","In CI, ensure the variable holding template paths is not empty before invoking"],"exampleFix":"// before (package.json)\n\"build:tpl\": \"handlebars -f dist/templates.js\"\n\n// after\n\"build:tpl\": \"handlebars src/templates/ -f dist/templates.js\"","handlingStrategy":"validation","validationCode":"const tplArgs = args.filter(a => !a.startsWith('-'));\nif (tplArgs.length === 0) {\n  throw new Error('handlebars CLI requires at least one template path or directory');\n}","typeGuard":null,"tryCatchPattern":"try {\n  execSync('handlebars ...');\n} catch (e) {\n  if (/Must define at least one template/.test(e.message)) {\n    // check that template paths/glob variables were expanded and non-empty\n  } else throw e;\n}","preventionTips":["Always pass an explicit template directory or file list to the CLI","In CI, fail fast if the variable holding template paths is empty","Test npm scripts locally before wiring them into pipelines","Quote globs deliberately and verify shell expansion behavior"],"tags":["handlebars","cli","precompiler","missing-argument"],"backgroundTag":"missing-cli-argument","analyzedSha":"13a7a679910d2adbfe7f6fad61ce8f98426b0378","analyzedAt":"2026-09-02T20:25:07.518Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}