facebook/docusaurus · error · Error

Versions should be strings. Found type "${typeof name}" for

Error message

Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(name)}.

What it means

Thrown by validateVersionName() (an `asserts name is string` guard). The function is called for each entry in versions.json. If an entry is not of type string (e.g. a number, boolean, object, or null), the build fails with the found type and a JSON dump of the value. This is the first of three sequential checks inside validateVersionName (type, non-empty, regex rules).

Source

Thrown at packages/docusaurus-plugin-content-docs/src/versions/validation.ts:13

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import _ from 'lodash';
import type {VersionsOptions} from '@docusaurus/plugin-content-docs';

export function validateVersionName(name: unknown): asserts name is string {
  if (typeof name !== 'string') {
    throw new Error(
      `Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(
        name,
      )}.`,
    );
  }
  if (!name.trim()) {
    throw new Error(
      `Invalid version name "${name}": version name must contain at least one non-whitespace character.`,
    );
  }
  const errors: [RegExp, string][] = [
    [/[/\\]/, 'should not include slash (/) or backslash (\\)'],
    [/.{33,}/, 'cannot be longer than 32 characters'],
    // eslint-disable-next-line no-control-regex
    [/[<>:"|?*\x00-\x1F]/, 'should be a valid file path'],
    [/^\.\.?$/, 'should not be "." or ".."'],
  ];

View on GitHub (pinned to 3f483e80e3)

Solutions

  1. Edit versions.json so every entry is a JSON string, e.g. ['1.4', '1.3'] not [1.4, 1.3].
  2. If generating versions.json programmatically, coerce each name with String(name) before writing.
  3. Validate the JSON shape before committing (it must be a flat array of strings).

Example fix

// versions.json - before
[1.4, 1.3]

// after
["1.4", "1.3"]
Defensive patterns

Strategy: type-guard

Validate before calling

const fs = require('fs');
function validateVersionsJsonTypes(filePath) {
  const json = JSON.parse(fs.readFileSync(filePath, 'utf8'));
  json.forEach((name, i) => {
    if (typeof name !== 'string') {
      throw new Error(`versions.json[${i}] is ${typeof name}, expected string: ${JSON.stringify(name)}`);
    }
  });
}

Type guard

function isStringArray(value) {
  return Array.isArray(value) && value.every((v) => typeof v === 'string');
}

Prevention

When it happens

Trigger: versions.json contains a numeric version like [1.4] instead of ['1.4']; a value is null or a boolean; the file was hand-edited and a key/value pair was inverted; a tool wrote version names as numbers.

Common situations: JSON authoring mistake (unquoted numbers); programmatic generation of versions.json without string coercion; corrupted or partially-merged versions.json.

Related errors


AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12). Data as JSON: /api/errors/b3dfcc10de7eadd6. Report an issue: GitHub.