You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Tesseract.js doesn't work on Cloudflare because it make it as browser env.
To Reproduce
Steps to reproduce the behavior:
install Tesseract on cloudflare sample project and just run.
the log is:
✘ [ERROR] ReferenceError: Worker is not defined
at module.exports
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]/node_modules/tesseract.js/src/worker/browser/spawnWorker.js:14:5)
at module.exports [as createWorker]
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]/node_modules/tesseract.js/src/createWorker.js:46:16)
at workerGen
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/src/index.ts:33:34)
at Array.<anonymous>
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/src/index.ts:16:15)
at Hono2.dispatch
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]/node_modules/hono/dist/hono-base.js:187:37)
at Hono2.fetch
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]/node_modules/hono/dist/hono-base.js:213:17)
at fetchDispatcher
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/.wrangler/tmp/bundle-2Cuv2V/middleware-loader.entry.ts:54:17)
at __facade_invokeChain__
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/wrangler/templates/middleware/common.ts:53:9)
at Object.next
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/wrangler/templates/middleware/common.ts:50:11)
at jsonError
(file:///Users/xxx/Workspace/WebstormProjects/podcast-backend/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
Please attach any input image required to replicate this behavior.
Expected behavior
It should be treat as node env but now is browser.
Device Version:
OS + Version: macOS 14.6.1 (23G93)
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
I assume you are talking about CloudFlare Workers. CloudFlare Workers do not use Node.js--they use a custom runtime that uses V8, and implements a handful of Node.js APIs. Therefore, the fact that the CloudFlare worker is deciding to use the browser path is probably an intentional design decision on CloudFlare's part.
Regardless of the browser vs. Node.js issue, the code in question is attempting to spawn a worker, and I do not believe it is possible to spawn a worker within a CloudFlare worker. For context, the Tesseract.js createWorker function spawns a worker that executes Tesseract jobs on a separate thread. This uses web workers in browser, and the worker_threads module in Node.js. My understanding of CloudFlare workers are that they are inherently single-threaded, so do not support spawning more threads.
To use Tesseract.js within a single thread, the worker code would need to be executed directly. Making the worker scripts run standalone would likely not be that difficult--this would presumably just require using src/worker-script/index.js directly after deleting the exports.dispatchHandlers stuff that communicates with the main thread.
Thanks for your explanation. I will try your suggestion.
Balearica
changed the title
Tesseract.js doesn't work on Cloudflare because it make it as browser env.
Tesseract.js doesn't work in CloudFlare Workers
Sep 25, 2024
Tesseract.js version 5.1.1
Describe the bug
Tesseract.js doesn't work on Cloudflare because it make it as browser env.
To Reproduce
Steps to reproduce the behavior:
Please attach any input image required to replicate this behavior.
Expected behavior
It should be treat as node env but now is browser.
Device Version:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: