{"record":{"id":"2a43cedb1a4e913e","repo":"naptha/tesseract.js","slug":"failed-to-load-tesseractcore","errorCode":null,"errorMessage":"Failed to load TesseractCore","messagePattern":"Failed to load TesseractCore","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/worker-script/browser/getCore.js","lineNumber":54,"sourceCode":"          corePathImportFile = `${corePathImport.replace(/\\/$/, '')}/tesseract-core-simd.wasm.js`;\n        }\n      } else if (lstmOnly) {\n        corePathImportFile = `${corePathImport.replace(/\\/$/, '')}/tesseract-core-lstm.wasm.js`;\n      } else {\n        corePathImportFile = `${corePathImport.replace(/\\/$/, '')}/tesseract-core.wasm.js`;\n      }\n    }\n\n    // Create a module named `global.TesseractCore`\n    global.importScripts(corePathImportFile);\n\n    // Tesseract.js-core versions through 4.0.3 create a module named `global.TesseractCoreWASM`,\n    // so we account for that here to preserve backwards compatibility.\n    // This part can be removed when Tesseract.js-core v4.0.3 becomes incompatible for other reasons\n    if (typeof global.TesseractCore === 'undefined' && typeof global.TesseractCoreWASM !== 'undefined' && typeof WebAssembly === 'object') {\n      global.TesseractCore = global.TesseractCoreWASM;\n    } else if (typeof global.TesseractCore === 'undefined') {\n      throw Error('Failed to load TesseractCore');\n    }\n    res.progress({ status: statusText, progress: 1 });\n  }\n  return global.TesseractCore;\n};\n","sourceCodeStart":36,"sourceCodeEnd":60,"githubUrl":"https://github.com/naptha/tesseract.js/blob/a1ca80d9e31c34512d0ded75ff8821ddcf3f2f91/src/worker-script/browser/getCore.js#L36-L60","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst worker = await createWorker('eng', 1, {\n  corePath: 'https://cdn.jsdelivr.net/npm/tesseract.js-core', // blocked by CSP\n});\n\n// after\nconst worker = await createWorker('eng', 1, {\n  corePath: '/vendor/tesseract-core/', // self-hosted, allowed in CSP script-src\n});","handlingStrategy":"validation","validationCode":"// Validate that corePath is reachable and is the .wasm.js loader, not the binary.\nasync function assertCoreReachable(corePath) {\n  const url = corePath.endsWith('.js')\n    ? corePath\n    : `${corePath.replace(/\\/$/, '')}/tesseract-core.wasm.js`;\n  const resp = await fetch(url, { method: 'HEAD' });\n  if (!resp.ok) throw new Error(`Core not reachable at ${url} (HTTP ${resp.status})`);\n  const ct = resp.headers.get('content-type') || '';\n  if (!/javascript|text|octet-stream/.test(ct) && ct !== '') {\n    throw new Error(`Core URL did not return a JS file (${ct})`);\n  }\n}\nawait assertCoreReachable(options.corePath || '/vendor/tesseract-core/');","typeGuard":"const isValidCorePath = (p) =>\n  typeof p === 'string' &&\n  (p.endsWith('.js') || !/\\.wasm$/.test(p)) &&\n  /^https?:\\/\\//.test(p) || p.startsWith('/');","tryCatchPattern":"try {\n  worker = await createWorker('eng', 1, { corePath });\n} catch (e) {\n  if (/Failed to load TesseractCore/i.test(e.message)) {\n    // fall back to the pinned CDN or a self-hosted copy\n    worker = await createWorker('eng', 1, { corePath: '/vendor/tesseract-core/' });\n  } else { throw e; }\n}","preventionTips":["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."],"tags":["core","browser","cdn","csp","configuration","offline"],"backgroundTag":null,"analyzedSha":"a1ca80d9e31c34512d0ded75ff8821ddcf3f2f91","analyzedAt":"2026-08-13T04:28:13.744Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}