hexojs/hexo · critical · TypeError

Invalid config detected: "url" should be string, not ${typeo

Error message

Invalid config detected: "url" should be string, not ${typeof config.url}!

What it means

Thrown by validate_config (lib/hexo/validate_config.ts:12) during Hexo startup. The url field in _config.yml must be a string. This check runs before URL parsing, so a non-string url (number, object, array, null after YAML quirks) is rejected with the actual type interpolated.

Source

Thrown at lib/hexo/validate_config.ts:12

import assert from 'assert';
import moment from 'moment-timezone';
import type Hexo from './index';

export = (ctx: Hexo): void => {
  const { config, log } = ctx;

  log.info('Validating config');

  // Validation for config.url && config.root
  if (typeof config.url !== 'string') {
    throw new TypeError(`Invalid config detected: "url" should be string, not ${typeof config.url}!`);
  }
  try {
    // eslint-disable-next-line no-new
    new URL(config.url);
    assert(new URL(config.url).protocol.startsWith('http'));
  } catch {
    throw new TypeError('Invalid config detected: "url" should be a valid URL!');
  }

  if (typeof config.root !== 'string') {
    throw new TypeError(`Invalid config detected: "root" should be string, not ${typeof config.root}!`);
  }
  if (config.root.trim().length <= 0) {
    throw new TypeError('Invalid config detected: "root" should not be empty!');
  }

  if (!config.timezone) {
    log.warn('No timezone setting detected! Using LocalTimeZone as the default timezone.');

View on GitHub (pinned to 059cb17494)

Solutions

  1. Open _config.yml and set url to a quoted http(s) string: url: https://example.com.
  2. If url is provided elsewhere (e.g. _config.<env>.yml or a plugin), ensure that source also yields a string.
  3. Search the codebase for assignments to config.url and fix any that set a non-string.
  4. Restart hexo after saving the config.

Example fix

# before (_config.yml)
url: 123

# after
url: https://example.com
Defensive patterns

Strategy: validation

Validate before calling

const url = hexo.config.url;
if (typeof url !== 'string') {
  throw new Error(`_config.yml 'url' must be a string, got ${typeof url}`);
}

Prevention

When it happens

Trigger: config.url is not a string: e.g. url: 123, url: [http://x], url: { href: ... } in _config.yml, or url omitted and defaulted to undefined. The validator runs on every hexo generate/server/launch.

Common situations: YAML parsing a bare number or colon-less token into a non-string; a theme/plugin overwriting config.url with an object; migrating a config and leaving url blank; environment-specific config override injecting a non-string.

Related errors


AI-assisted analysis of hexojs/hexo@059cb17494 (2026-08-12). Data as JSON: /api/errors/e536747568e3b1b6. Report an issue: GitHub.