A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/naptha/tesseract.js/issues/925 below:

createWorker throws exception with option.langPath set in electron · Issue #925 · naptha/tesseract.js · GitHub

Tesseract.js version (version number for npm/GitHub release, or specific commit for repo)
"tesseract.js": "^5.1.0",
Describe the bug
When using tesseract.js in the electron environment, setting option.langPath to a local file path, the createWorker function results in an error.
The following code snippet and error message demonstrate the issue:

const worker: Promise<Tesseract.Worker> = createWorker("chi_sim", 1, {
  langPath: path.join(__dirname, "../../resources/ocr")
});

error:

Error: TypeError: Only absolute URLs are supported
    at Worker.<anonymous> (/path/to/node_modules/.pnpm/tesseract.js@5.1.0/node_modules/tesseract.js/src/createWorker.js:248:15)
    at Worker.emit (node:events:518:28)
    at Worker.emit (node:domain:488:12)
    at MessagePort.<anonymous> (node:internal/worker:262:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Upon examining the code, I found that the condition below appears to be arbitrary since in the electron environment, it should be able to load a language file from a local path as well.

// For Node.js, langPath may be a URL or local file path // The is-url package is used to tell the difference // For the browser version, langPath is assumed to be a URL if (env !== 'node' || isURL(langPathDownload) || langPathDownload.startsWith('moz-extension://') || langPathDownload.startsWith('chrome-extension://') || langPathDownload.startsWith('file://')) { /** When langPathDownload is an URL */ path = langPathDownload.replace(/\/$/, ''); }

Expected behavior
It should be able to load a language file from a local path in the electron environment.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4