{"record":{"id":"9cb2ac63884bfa32","repo":"PaddlePaddle/PaddleOCR","slug":"worker-mode-does-not-support-a-custom-fetch-implem","errorCode":null,"errorMessage":"worker mode does not support a custom fetch implementation.","messagePattern":"worker mode does not support a custom fetch implementation\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"paddleocr-js/packages/core/src/pipelines/ocr/index.ts","lineNumber":80,"sourceCode":"\n  [key: string]: unknown;\n}\n\nexport class PaddleOCR extends OcrPipelineRunner {\n  constructor(options: OcrPipelineRunnerOptions) {\n    super({\n      ...options,\n      ensureServedFromHttp,\n      sourceToMat\n    });\n  }\n\n  static async create(\n    options: PaddleOCRCreateOptions = {}\n  ): Promise<PaddleOCR | WorkerBackedPaddleOCR> {\n    const workerOptions = resolveWorkerOptions(options.worker);\n    if (workerOptions.enabled && options.fetch) {\n      throw new Error(\"worker mode does not support a custom fetch implementation.\");\n    }\n\n    const resolvedOptions = resolvePaddleOCROptions(options);\n    const instance = workerOptions.enabled\n      ? createWorkerBackedPaddleOCR(resolvedOptions, {\n          createWorker: workerOptions.createWorker ?? undefined\n        })\n      : new PaddleOCR({\n          ...resolvedOptions,\n          fetch: options.fetch\n        });\n\n    if (options.initialize !== false) {\n      await instance.initialize();\n    }\n    return instance;\n  }\n}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr-js/packages/core/src/pipelines/ocr/index.ts#L62-L98","documentation":"PaddleOCR.create() throws this when you enable worker mode (options.worker is true or an options object) and also pass a custom fetch implementation (options.fetch). In worker mode the pipeline runs inside a Web Worker and fetch cannot be serialized or transferred across the worker boundary, so the combination is rejected up front rather than silently ignored.","triggerScenarios":"Calling PaddleOCR.create({ worker: true, fetch: myFetch }) or PaddleOCR.create({ worker: { createWorker: () => new Worker(...) }, fetch: customFetch }). resolveWorkerOptions() returns enabled=true and options.fetch is truthy.","commonSituations":"Adding a fetch wrapper (auth headers, proxying, offline caching) to an existing integration and then turning on worker mode for performance; copying a main-thread configuration object into a worker-mode create() call.","solutions":["Remove the fetch option when worker mode is enabled; the worker performs its own fetches.","If you need custom networking, keep worker disabled (worker: false or unset) so fetch is honored on the main thread.","If the custom fetch exists for asset URL rewriting, instead override the model/asset URLs via model selection options (e.g. *_model_dir / ModelAsset) which are plain data and worker-safe."],"exampleFix":"// before\nconst ocr = await PaddleOCR.create({ worker: true, fetch: authedFetch });\n\n// after\nconst ocr = await PaddleOCR.create({ worker: true });\n// or keep custom fetch on the main thread:\nconst ocr = await PaddleOCR.create({ fetch: authedFetch });","handlingStrategy":"validation","validationCode":"// Before create(): worker + fetch are mutually exclusive\nconst wantsWorker = options.worker === true || (typeof options.worker === 'object' && options.worker !== null);\nif (wantsWorker && options.fetch) {\n  throw new TypeError('Custom fetch is not supported with worker: true. Remove fetch or disable worker mode.');\n}","typeGuard":"function isSafeCreateOptions(o: { worker?: unknown; fetch?: unknown }): boolean {\n  const workerEnabled = o.worker === true || (typeof o.worker === 'object' && o.worker !== null);\n  return !(workerEnabled && o.fetch != null);\n}","tryCatchPattern":"try {\n  const ocr = await PaddleOCR.create(opts);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('does not support a custom fetch')) {\n    // retry without fetch (worker performs its own fetching)\n    const { fetch: _f, ...rest } = opts;\n    return PaddleOCR.create(rest);\n  }\n  throw e;\n}","preventionTips":["Centralize PaddleOCR.create() in one factory function that asserts worker and fetch are never both set.","Document in your config schema that customFetch and workerMode are mutually exclusive."],"tags":["worker","configuration","fetch","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}