mozilla/pdf.js · error · Error
Ensure that the `${kind}` API parameter is provided.
Error message
Ensure that the `${kind}` API parameter is provided. What it means
Thrown by BaseBinaryDataFactory.fetch({ kind, filename }) when this[kind] is falsy, i.e., the corresponding configuration parameter was not supplied. The factory is used internally to load CMap binary files (cMapUrl), standard font metrics (standardFontDataUrl), and WASM decoders such as OpenJPEG (wasmUrl). Without a base URL there is no place to fetch the resource from.
Source
Thrown at src/display/binary_data_factory.js:49
unreachable("Cannot initialize BaseBinaryDataFactory.");
}
this.cMapUrl = cMapUrl;
this.standardFontDataUrl = standardFontDataUrl;
this.wasmUrl = wasmUrl;
}
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 {View on GitHub (pinned to 5903d58d58)
Solutions
- Install pdfjs-dist's cmaps and standard fonts assets and point cMapUrl / standardFontDataUrl at them (with trailing '/').
- If you ship JPEG2000 support, set wasmUrl to the folder containing the openjpeg wasm.
- Confirm the URLs resolve over HTTP (200) before relying on them.
Example fix
// before
getDocument({ data });
// after
getDocument({
data,
cMapUrl: 'https://cdn.example.com/cmaps/',
standardFontDataUrl: 'https://cdn.example.com/standard_fonts/',
}); Defensive patterns
Strategy: validation
Validate before calling
function validatePdfjsConfig(cfg) {
const needed = [];
if (cfg.useCMaps && !cfg.cMapUrl) needed.push('cMapUrl');
if (!cfg.standardFontDataUrl) needed.push('standardFontDataUrl');
if (needed.length) throw new Error('Missing pdfjs config: ' + needed.join(', '));
}
validatePdfjsConfig(config); Type guard
null
Try / catch
null
Prevention
- Always configure cMapUrl when you may render CJK content.
- Always configure standardFontDataUrl when fonts may be unembedded.
- Document the asset folders your bundle must ship alongside pdfjs-dist.
When it happens
Trigger: Loading a CJK PDF without configuring cMapUrl; a PDF using a non-embedded standard font without standardFontDataUrl; a JPEG2000 image when openjpeg WASM is required but wasmUrl is unset.
Common situations: Self-hosting pdfjs-dist and forgetting the /cmaps/ and /standard_fonts/ asset folders; bundle configs that tree-shake the wasmUrl; moving from the legacy build (which had bundled bcmaps) to the modular one.
Related errors
- Invalid factory url: "${val}" must include trailing slash.
- No ICC color space support
- JBig2 failed to initialize
- Unable to load ${this.#errorStr[kind]} data at: ${url}
- response.statusText
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/5b143c3485b9bff6.
Report an issue: GitHub.