Skip to content

Tesseract.js doesn't work in CloudFlare Workers #950

@penkzhou

Description

@penkzhou

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:

  1. install Tesseract on cloudflare sample project and just run.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions