mozilla/pdf.js · error · Error
Failed to fetch file "${url}" with "${response.statusText}".
Error message
Failed to fetch file "${url}" with "${response.statusText}". What it means
Thrown by fetchBinaryData when the HTTP fetch resolves with response.ok === false. The helper is used internally to load .bcmap CMap files and standard-font metric files; the error message includes the URL and statusText so the missing asset is identifiable. It is a wrapper around the browser fetch() that turns non-2xx responses into exceptions.
Source
Thrown at src/core/core_utils.js:127
}
let dataLength = 0;
for (let i = 0; i < length; i++) {
dataLength += arr[i].byteLength;
}
const data = new Uint8Array(dataLength);
let pos = 0;
for (let i = 0; i < length; i++) {
const item = new Uint8Array(arr[i]);
data.set(item, pos);
pos += item.byteLength;
}
return data;
}
async function fetchBinaryData(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`Failed to fetch file "${url}" with "${response.statusText}".`
);
}
return response.bytes();
}
/**
* Get the value of an inheritable property.
*
* If the PDF specification explicitly lists a property in a dictionary as
* inheritable, then the value of the property may be present in the dictionary
* itself or in one or more parents of the dictionary.
*
* If the key is not found in the tree, `undefined` is returned. Otherwise,
* the value for the key is returned or, if `stopWhenFound` is `false`, a list
* of values is returned.
*
* @param {Dict} dict - Dictionary from where to start the traversal.View on GitHub (pinned to 5903d58d58)
Solutions
- Ship cmaps/ and standard_fonts/ from pdfjs-dist and set cMapUrl/standardFontDataUrl to their absolute, correctly-slash-terminated paths.
- Verify each URL returns 200 in a browser devtools network panel (watch for 404 or CORS errors).
- Serve the assets with permissive CORS headers if the worker origin differs from the asset origin.
- If assets cannot be hosted at a URL, provide a custom fetchBuiltInCMap / standard-font loader that resolves them from local bytes.
Example fix
// before
getDocument({ url, cMapUrl: '/cmaps' }); // no trailing slash, packed unset
// after
getDocument({
url,
cMapUrl: '/assets/cmaps/',
cMapPacked: true,
standardFontDataUrl: '/assets/standard_fonts/',
}); Defensive patterns
Strategy: try-catch
Validate before calling
// Probe asset URLs at app startup so a missing CMap/font fails fast and visibly
async function assertAssetOk(url) {
const res = await fetch(url, { method: 'HEAD' });
if (!res.ok) throw new Error(`Missing pdf.js asset: ${url} (${res.status})`);
}
await assertAssetOk(`${cMapUrl}78-RKSJ-H.bcmap`); Try / catch
try {
await loadingTask.promise;
} catch (e) {
if (/Failed to fetch file/.test(e.message)) {
console.error('CMap/standard-font asset unreachable - check cMapUrl/standardFontDataUrl/CORS', e);
} else throw e;
} Prevention
- Always ship cmaps/ and standard_fonts/ from pdfjs-dist alongside the worker.
- Set cMapUrl and standardFontDataUrl to absolute, slash-terminated paths.
- Verify each asset URL returns 200 and permissive CORS headers in DevTools.
- Add a CI smoke test that loads a CJK + standard-font PDF against your deployment.
- For offline/node usage, provide a custom fetchBuiltInCMap that reads local files.
When it happens
Trigger: getDocument configured with cMapUrl or standardFontDataUrl pointing at a path that returns 4xx/5xx (404 is most common); CORS preflight rejection; the asset server is down or returns an error status.
Common situations: Deployments that copy pdf.js/pdf.worker.js but forget to ship the cmaps/ and standard_fonts/ directories from pdfjs-dist; a wrong or missing trailing slash in cMapUrl; CORS blocking cross-origin asset fetches from the worker.
Related errors
- Unknown CMap name: ${name}
- Built-in CMap parameters are not provided.
- unexpected EOF in bcmap
- mapCidRange - ignoring data above MAX_MAP_RANGE.
- mapBfRange - ignoring data above MAX_MAP_RANGE.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/3085958d1edda3f4.
Report an issue: GitHub.