mozilla/pdf.js · error · Error

Unable to load ${this.#errorStr[kind]} data at: ${url}

Error message

Unable to load ${this.#errorStr[kind]} data at: ${url}

What it means

Thrown by BaseBinaryDataFactory.fetch when the underlying _fetch(url, kind) call rejects. The wrapper swallows the original reason and rethrows a generic 'Unable to load <CMap|font|wasm> data at: <url>' message. It indicates the resource URL was constructed but the network/CORS/HTTP request failed.

Source

Thrown at src/display/binary_data_factory.js:54

  }

  async fetch({ kind, filename }) {
    switch (kind) {
      case "cMapUrl":
      case "standardFontDataUrl":
      case "wasmUrl":
        break;
      default:
        unreachable(`Not implemented: ${kind}`);
    }
    const baseUrl = this[kind];
    if (!baseUrl) {
      throw new Error(`Ensure that the \`${kind}\` API parameter is provided.`);
    }
    const url = `${baseUrl}${filename}`;

    return this._fetch(url, kind).catch(reason => {
      throw new Error(`Unable to load ${this.#errorStr[kind]} data at: ${url}`);
    });
  }

  /**
   * @ignore
   * @returns {Promise<Uint8Array>}
   */
  async _fetch(url, kind) {
    unreachable("Abstract method `_fetch` called.");
  }
}

class DOMBinaryDataFactory extends BaseBinaryDataFactory {
  /**
   * @ignore
   */
  async _fetch(url, kind) {
    const type =

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Open the printed URL in a browser and confirm it returns 200 with correct CORS headers.
  2. Verify the cMapUrl/standardFontDataUrl/wasmUrl base path matches the installed pdfjs-dist version.
  3. If cross-origin, add Access-Control-Allow-Origin on the asset host, or host the assets same-origin.

Example fix

// before (broken path)
getDocument({ data, cMapUrl: 'https://cdn.example.com/cmaps/' });

// after
getDocument({ data, cMapUrl: '/assets/pdfjs/cmaps/' });
// ensure /assets/pdfjs/cmaps/ is served and same-origin
Defensive patterns

Strategy: try-catch

Validate before calling

async function assertAssetReachable(baseUrl, probeFile) {
  const r = await fetch(baseUrl + probeFile, { method: 'HEAD' });
  if (!r.ok) throw new Error(`Asset unreachable: ${baseUrl}${probeFile} -> ${r.status}`);
}
// at startup:
await assertAssetReachable(config.cMapUrl, 'GBK-EUC-H.bcmap');

Type guard

null

Try / catch

try {
  await render();
} catch (e) {
  if (/Unable to load (CMap|font|wasm) data at/.test(e.message)) {
    // log the URL and surface a config error to the user
  } else throw e;
}

Prevention

When it happens

Trigger: 404 for a missing CMap or font metrics file; CORS rejection when the asset host lacks Access-Control-Allow-Origin; offline/network failure; misconfigured cMapUrl/standardFontDataUrl/wasmUrl base.

Common situations: CDN mis-routes after a version bump (asset path changed); dev server not serving the /cmaps folder; cross-origin requests in browsers without proper CORS headers; self-hosted assets behind auth.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/7e644ddd9c7e9509. Report an issue: GitHub.