naptha/tesseract.js · critical · Error
Failed to load TesseractCore
Error message
Failed to load TesseractCore
What it means
In the browser worker, getCore.js resolves a core JS file (defaulting to the jsdelivr CDN, picking SIMD/relaxed-SIMD/LSTM variants) and calls importScripts() on it. After the import it expects global.TesseractCore to be defined (with a fallback to global.TesseractCoreWASM for core <= 4.0.3). If neither exists, it throws 'Failed to load TesseractCore'.
Source
Thrown at src/worker-script/browser/getCore.js:54
corePathImportFile = `${corePathImport.replace(/\/$/, '')}/tesseract-core-simd.wasm.js`;
}
} else if (lstmOnly) {
corePathImportFile = `${corePathImport.replace(/\/$/, '')}/tesseract-core-lstm.wasm.js`;
} else {
corePathImportFile = `${corePathImport.replace(/\/$/, '')}/tesseract-core.wasm.js`;
}
}
// Create a module named `global.TesseractCore`
global.importScripts(corePathImportFile);
// Tesseract.js-core versions through 4.0.3 create a module named `global.TesseractCoreWASM`,
// so we account for that here to preserve backwards compatibility.
// This part can be removed when Tesseract.js-core v4.0.3 becomes incompatible for other reasons
if (typeof global.TesseractCore === 'undefined' && typeof global.TesseractCoreWASM !== 'undefined' && typeof WebAssembly === 'object') {
global.TesseractCore = global.TesseractCoreWASM;
} else if (typeof global.TesseractCore === 'undefined') {
throw Error('Failed to load TesseractCore');
}
res.progress({ status: statusText, progress: 1 });
}
return global.TesseractCore;
};
View on GitHub (pinned to a1ca80d9e3)
Solutions
- Self-host the matching tesseract.js-core version and set corePath to that directory or to the specific .wasm.js file.
- Add the core origin (CDN or self-hosted) to the script-src directive of your Content-Security-Policy.
- Verify network access to the core URL from the browser (open it directly / check devtools).
- Ensure corePath ends in a directory (lib loads tesseract-core*.wasm.js) or a full .wasm.js filename — never the raw .wasm binary.
Example fix
// before
const worker = await createWorker('eng', 1, {
corePath: 'https://cdn.jsdelivr.net/npm/tesseract.js-core', // blocked by CSP
});
// after
const worker = await createWorker('eng', 1, {
corePath: '/vendor/tesseract-core/', // self-hosted, allowed in CSP script-src
}); Defensive patterns
Strategy: validation
Validate before calling
// Validate that corePath is reachable and is the .wasm.js loader, not the binary.
async function assertCoreReachable(corePath) {
const url = corePath.endsWith('.js')
? corePath
: `${corePath.replace(/\/$/, '')}/tesseract-core.wasm.js`;
const resp = await fetch(url, { method: 'HEAD' });
if (!resp.ok) throw new Error(`Core not reachable at ${url} (HTTP ${resp.status})`);
const ct = resp.headers.get('content-type') || '';
if (!/javascript|text|octet-stream/.test(ct) && ct !== '') {
throw new Error(`Core URL did not return a JS file (${ct})`);
}
}
await assertCoreReachable(options.corePath || '/vendor/tesseract-core/'); Type guard
const isValidCorePath = (p) =>
typeof p === 'string' &&
(p.endsWith('.js') || !/\.wasm$/.test(p)) &&
/^https?:\/\//.test(p) || p.startsWith('/'); Try / catch
try {
worker = await createWorker('eng', 1, { corePath });
} catch (e) {
if (/Failed to load TesseractCore/i.test(e.message)) {
// fall back to the pinned CDN or a self-hosted copy
worker = await createWorker('eng', 1, { corePath: '/vendor/tesseract-core/' });
} else { throw e; }
} Prevention
- Self-host the exact tesseract.js-core version that matches your tesseract.js runtime.
- Add the core origin to your CSP script-src; do not rely on unsafe-eval or inline scripts.
- Point corePath at a directory or a full .wasm.js filename, never the raw .wasm binary.
- Pin dependency versions to avoid silent core/runtime version drift across releases.
When it happens
Trigger: corePath pointing to a missing file or wrong directory; CSP script-src blocking the CDN or self-hosted origin; offline with no local core; importScripts silently failing (network/CSP); pointing corePath at a .wasm binary instead of the .wasm.js loader; core version mismatch with the tesseract.js runtime.
Common situations: Production deployment behind a strict Content-Security-Policy; air-gapped intranet; self-hosting the core but with a path typo; CDN blocked in the user's region; pinning an incompatible tesseract.js-core version.
Related errors
- Network error while fetching ${fetchUrl}. Response code: ${r
- Legacy model requested but code missing.
- `worker.detect` requires Legacy model, which was not loaded.
- initialization failed
- File could not be read! Code=${code}
AI-assisted analysis of naptha/tesseract.js@a1ca80d9e3 (2026-08-13).
Data as JSON: /api/errors/2a43cedb1a4e913e.
Report an issue: GitHub.