{"record":{"id":"1814e3a7933a2e11","repo":"handlebars-lang/handlebars.js","slug":"name-missing-for-template","errorCode":null,"errorMessage":"Name missing for template","messagePattern":"Name missing for template","errorType":"exception","errorClass":"Handlebars.Exception","httpStatus":null,"severity":"error","filePath":"lib/precompiler.js","lineNumber":238,"sourceCode":"    }\n\n    let precompiled = Handlebars.precompile(template.source, options);\n\n    // If we are generating a source map, we have to reconstruct the SourceNode object\n    if (opts.map) {\n      let consumer = await new SourceMapConsumer(precompiled.map);\n      precompiled = SourceNode.fromStringWithSourceMap(\n        precompiled.code,\n        consumer\n      );\n      consumer.destroy();\n    }\n\n    if (opts.simple) {\n      output.add([precompiled, '\\n']);\n    } else {\n      if (!template.name) {\n        throw new Handlebars.Exception('Name missing for template');\n      }\n\n      output.add([\n        objectName,\n        \"['\",\n        template.name,\n        \"'] = template(\",\n        precompiled,\n        ');\\n',\n      ]);\n    }\n  }\n\n  // Output the content\n  if (!opts.simple) {\n    output.add('})();');\n  }\n","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/handlebars-lang/handlebars.js/blob/13a7a679910d2adbfe7f6fad61ce8f98426b0378/lib/precompiler.js#L220-L256","documentation":"In non-simple mode the CLI registers each precompiled template under a name; when a template has no name (usually an unnamed file/stdin input), the generator throws because it cannot build the Handlebars.templates['name'] entry.","triggerScenarios":"Running the CLI in default (non-simple) mode with a template that has no name — e.g. piping via stdin or an input that produced no derived name.","commonSituations":"cat template.hbs | handlebars (stdin has no filename); renaming/normalization logic stripping the extension left an empty name; unusual file layouts where the name can't be derived.","solutions":["Pass templates as named files/directories rather than stdin so a name can be derived","Use -s/--simple mode if you intentionally compile one anonymous template","Ensure the input file has a valid filename (extension stripped becomes the template name)"],"exampleFix":"// before\ncat src/templates/home.hbs | handlebars -f dist/tpl.js\n\n// after\nhandlebars src/templates/home.hbs -f dist/tpl.js\n// or for anonymous output\nhandlebars -s src/templates/home.hbs -f dist/home.js","handlingStrategy":"validation","validationCode":"if (!flags.simple && (!inputFile || inputFile === '/dev/stdin')) {\n  throw new Error('Non-simple CLI mode needs a named template file (stdin has no name)');\n}","typeGuard":"function isNamedTemplate(t) {\n  return typeof t.name === 'string' && t.name.length > 0;\n}","tryCatchPattern":"try {\n  execSync(cliCmd);\n} catch (e) {\n  if (/Name missing for template/.test(e.message)) {\n    // pass a named file instead of stdin, or add -s for anonymous output\n  } else throw e;\n}","preventionTips":["Always compile from named files/directories, not stdin, in non-simple mode","Use -s when an anonymous single template is the goal","Keep template files with valid base names (the name derives from the filename)"],"tags":["handlebars","cli","precompiler","missing-name"],"backgroundTag":"missing-template-name","analyzedSha":"13a7a679910d2adbfe7f6fad61ce8f98426b0378","analyzedAt":"2026-09-02T20:25:07.518Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}