{"record":{"id":"86c0309514e889f6","repo":"naptha/tesseract.js","slug":"worker-detect-requires-legacy-model-which-was-n","errorCode":null,"errorMessage":"`worker.detect` requires Legacy model, which was not loaded.","messagePattern":"`worker\\.detect` requires Legacy model, which was not loaded\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/createWorker.js","lineNumber":179,"sourceCode":"    startJob(createJob({\n      id: jobId,\n      action: 'setParameters',\n      payload: { params },\n    }))\n  );\n\n  const recognize = async (image, opts = {}, output = {\n    text: true,\n  }, jobId) => (\n    startJob(createJob({\n      id: jobId,\n      action: 'recognize',\n      payload: { image: await loadImage(image), options: opts, output },\n    }))\n  );\n\n  const detect = async (image, jobId) => {\n    if (lstmOnlyCore) throw Error('`worker.detect` requires Legacy model, which was not loaded.');\n\n    return startJob(createJob({\n      id: jobId,\n      action: 'detect',\n      payload: { image: await loadImage(image) },\n    }));\n  };\n\n  const terminate = async () => {\n    if (worker !== null) {\n      /*\n      await startJob(createJob({\n        id: jobId,\n        action: 'terminate',\n      }));\n      */\n      terminateWorker(worker);\n      worker = null;","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/naptha/tesseract.js/blob/a1ca80d9e31c34512d0ded75ff8821ddcf3f2f91/src/createWorker.js#L161-L197","documentation":"worker.detect() runs Tesseract's DetectOS, which depends on legacy engine components absent from the LSTM-only core. The guard at src/createWorker.js:179 checks lstmOnlyCore and throws before sending any job to the worker thread. detect() therefore requires a worker built with the full core.","triggerScenarios":"Calling worker.detect(image) on a worker created with default options (OEM.LSTM_ONLY, no legacyCore flag).","commonSituations":"Using defaults and wanting orientation/script detection; copying detect() from docs without reading the legacy-core requirement; wanting OSD on a minimal-size build.","solutions":["Create the worker with { legacyCore: true, legacyLang: true } so the legacy engine and language data are available.","Create the worker with OEM.TESSERACT_ONLY or OEM.TESSERACT_LSTM_COMBINED, which forces legacy core/lang.","Drop detect() and call recognize() with output.layoutBlocks = true to get layout info from the LSTM engine."],"exampleFix":"// before\nconst worker = await createWorker('eng'); // LSTM-only\nconst { data } = await worker.detect(img); // throws\n\n// after\nconst worker = await createWorker('eng', OEM.TESSERACT_LSTM_COMBINED, { legacyCore: true, legacyLang: true });\nconst { data } = await worker.detect(img);","handlingStrategy":"validation","validationCode":"// Track whether the worker was built with legacy support.\nconst legacyEnabled = options.legacyCore === true || oem === 0 || oem === 2;\nasync function safeDetect(worker, image, legacyEnabled) {\n  if (!legacyEnabled) {\n    throw new Error('detect() needs legacy core; recreate worker with legacyCore:true');\n  }\n  return worker.detect(image);\n}\nconst r = await safeDetect(worker, image, legacyEnabled);","typeGuard":"const workerSupportsDetect = (creationOem, options) =>\n  creationOem === 0 /* TESSERACT_ONLY */ ||\n  creationOem === 2 /* TESSERACT_LSTM_COMBINED */ ||\n  options?.legacyCore === true;","tryCatchPattern":"try {\n  await worker.detect(image);\n} catch (e) {\n  if (/Legacy model.*not loaded/i.test(e.message)) {\n    await worker.terminate();\n    worker = await createWorker('eng', 2, { legacyCore: true, legacyLang: true });\n    return worker.detect(image);\n  }\n  throw e;\n}","preventionTips":["If you may call detect(), create the worker with OEM.TESSERACT_LSTM_COMBINED and legacyCore/legacyLang from the start.","Prefer recognize() with output.layoutBlocks for layout info when you cannot afford the legacy build size.","Document per worker instance whether detect() is available, derived from its creation OEM/options."],"tags":["oem","legacy-core","detect","configuration"],"backgroundTag":null,"analyzedSha":"a1ca80d9e31c34512d0ded75ff8821ddcf3f2f91","analyzedAt":"2026-08-13T04:28:13.744Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}