facebook/docusaurus · error · Error

Couldn't find any doc with id "${docId}" in version${version

Error message

Couldn't find any doc with id "${docId}" in version${versions.length > 1 ? 's' : ''} "${versions.map((version) => version.name).join(', ')}".
Available doc ids are:
- ${uniq(allDocs.map((versionDoc) => versionDoc.id)).join('\n- ')}

What it means

Thrown by useLayoutDoc() when no doc with the given docId exists in any candidate version AND the id is not a draft. It searches all docs across versions (active + preferred + latest via useDocsVersionCandidates); a miss first checks whether the id is a draft (draftIds), in which case it returns null silently (drafts are intentionally filtered). Only non-draft, non-existent ids throw, and the message lists all available doc ids to help correct the reference. Like useLayoutDocsSidebar, this is for layout components that resolve a doc link from any page.

Source

Thrown at packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx:369

 * @throws This hook throws if a doc with said ID is not found.
 */
export function useLayoutDoc(
  docId: string,
  docsPluginId?: string,
): GlobalDoc | null {
  const versions = useDocsVersionCandidates(docsPluginId);
  return useMemo(() => {
    const allDocs = versions.flatMap((version) => version.docs);
    const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
    if (!doc) {
      const isDraft = versions
        .flatMap((version) => version.draftIds)
        .includes(docId);
      // Drafts should be silently filtered instead of throwing
      if (isDraft) {
        return null;
      }
      throw new Error(
        `Couldn't find any doc with id "${docId}" in version${
          versions.length > 1 ? 's' : ''
        } "${versions.map((version) => version.name).join(', ')}".
Available doc ids are:
- ${uniq(allDocs.map((versionDoc) => versionDoc.id)).join('\n- ')}`,
      );
    }
    return doc;
  }, [docId, versions]);
}

// TODO later read version/route directly from context
/**
 * The docs plugin creates nested routes, with the top-level route providing the
 * version metadata, and the subroutes creating individual doc pages. This hook
 * will match the current location against all known sub-routes.
 *
 * @param props The props received by `@theme/DocRoot`

View on GitHub (pinned to 3f483e80e3)

Solutions

  1. Read the 'Available doc ids' list in the error and correct the docId to a valid one.
  2. Search the docs (including versioned_docs) for the exact id string to confirm spelling/slashes.
  3. If the doc is in a different docs plugin, pass the right docsPluginId to useLayoutDoc.
  4. If the doc was intentionally removed, delete the stale navbar/layout reference too.

Example fix

// before
navbar: [{ to: '/docs/intro', label: 'Intro', docId: 'introo' }]
// after: fix the typo
navbar: [{ to: '/docs/intro', label: 'Intro', docId: 'intro' }]
Defensive patterns

Strategy: validation

Validate before calling

import {useDocsVersionCandidates} from '@docusaurus/plugin-content-docs/client';

function useKnownDocId(docId: string, docsPluginId?: string) {
  const versions = useDocsVersionCandidates(docsPluginId);
  const allIds = versions.flatMap((v) => v.docs.map((d) => d.id));
  const isDraft = versions.flatMap((v) => v.draftIds).includes(docId);
  return {exists: allIds.includes(docId), isDraft, available: allIds} as const;
}
// const check = useKnownDocId('intro'); if (!check.exists && !check.isDraft) return null;

Type guard

const isKnownDocId = (
  id: string,
  versions: {docs: {id: string}[]; draftIds: string[]}[],
): boolean => versions.some((v) => v.docs.some((d) => d.id === id));

Prevention

When it happens

Trigger: A navbar item, footer link, or layout component references a docId that was renamed, deleted, or never existed; the doc exists only in a different docs plugin id; a typo in the docId string. The throw is inside useMemo so it fires during render of the layout component.

Common situations: Renaming a doc (changing its id/slug) without updating config references; deleting a doc while navbar still links to its id; docsPluginId mismatch when multiple docs plugins are configured; referencing a doc that exists only in an older non-candidate version.

Related errors


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