tesseract.js icon indicating copy to clipboard operation
tesseract.js copied to clipboard

Sveltekit TypeError

Open HannesGitH opened this issue 3 years ago • 0 comments

Bug Description

When using the npm module (v2.1.5) in a sveltekit project the server crashes with:

[path]\node_modules\tesseract.js\src\createWorker.js:173
        throw Error(data);
        ^

Error: TypeError: Cannot convert undefined or null to object
    at ChildProcess.<anonymous> ([path]\node_modules\tesseract.js\src\createWorker.js:173:15)
    at ChildProcess.emit (node:events:390:28)
    at emit (node:internal/child_process:917:12)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

(This only happens when trying to run in the browser e.g. via the onMount hook. otherwise it runs fine in the browser until the status is "api initialized" it then only continues server-side and succeeds there might be something to blame on vite etc. )

Steps to reproduce the behavior:

  1. create sveltekit project npm init svelte@next ..
  2. install tesseract module npm i tesseract.js
  3. import into svelte (or imported js/ts) file
  4. use

expected behaviour

The client side version of this module should be used to retrieve the text


feature request

converting this to a feature request in case i'm just not experienced enought (most probable):

please add an example project (similar to the vue/angular/react one) using sveltekit and this npm module.

HannesGitH avatar Jan 17 '22 09:01 HannesGitH

If this issue is still active, please provide a reproducible example in the form of a code snippet or project repo that can be cloned.

Balearica avatar Sep 03 '22 22:09 Balearica

i tried again with a newer svelte version, seems to work now, thanks

HannesGitH avatar Sep 17 '22 13:09 HannesGitH

ok, the module works fine if used as a standalone (like in this mre)

but as soon as i try to export import this like here it doesnt work, seemingly because the svelte stores get triggered automatically initially on module import and that would trigger the worker creation (which doesnt work this early in the rendering yet) or something idk, but thats most probably on me since im not experienced with this

HannesGitH avatar Sep 19 '22 12:09 HannesGitH