hexojs/hexo · error · TypeError
name is required
Error message
name is required
What it means
Thrown by Tag.register when the 'name' argument is falsy. Tags are custom template tags (e.g. blockquote, codepen) added to the Nunjucks environment by name; an empty name cannot be registered as a Nunjucks extension.
Source
Thrown at lib/extend/tag.ts:220
/**
* A tag allows users to quickly and easily insert snippets into their posts.
*/
class Tag {
public env: Environment;
public source: string;
constructor() {
this.env = new Environment(null, {
autoescape: false
});
}
register(name: string, fn: TagFunction): void
register(name: string, fn: TagFunction, ends: boolean): void
register(name: string, fn: TagFunction, options: RegisterOptions): void
register(name: string, fn: TagFunction, options?: RegisterOptions | boolean):void {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');
if (options == null || typeof options === 'boolean') {
options = { ends: options as boolean };
}
let tag: NunjucksTag;
if (options.async) {
let asyncFn: AsyncTagFunction;
if (fn.length > 2) {
asyncFn = Promise.promisify(fn);
} else {
asyncFn = Promise.method(fn);
}
if (options.ends) {
tag = new NunjucksAsyncBlock(name, asyncFn);View on GitHub (pinned to 059cb17494)
Solutions
- Pass a non-empty tag name string.
- Validate the name source before registering.
- Ensure the name is a valid Nunjucks extension identifier.
Example fix
// before hexo.extend.tag.register(tagName, fn); // after if (tagName) hexo.extend.tag.register(tagName, fn);
Defensive patterns
Strategy: validation
Validate before calling
if (!name) throw new Error('tag name required');
hexo.extend.tag.register(name, fn); Type guard
const isValidName = (n: unknown): n is string => typeof n === 'string' && n.length > 0;
Prevention
- Read tag names from a constant map with non-empty keys.
- Validate name in a shared registerTag helper.
- Test the tag is callable in a template after registration.
When it happens
Trigger: Calling hexo.extend.tag.register('', fn) or register(undefined, fn).
Common situations: A tag plugin reads its name from a config field that is empty, or a loop registers tags from a partial map producing undefined keys.
Related errors
AI-assisted analysis of hexojs/hexo@059cb17494 (2026-08-12).
Data as JSON: /api/errors/c30536cb27821fca.
Report an issue: GitHub.