{"record":{"id":"53024830787fc22b","repo":"mozilla/pdf.js","slug":"no-globalworkeroptions-workersrc-specified","errorCode":null,"errorMessage":"No \"GlobalWorkerOptions.workerSrc\" specified.","messagePattern":"No \"GlobalWorkerOptions\\.workerSrc\" specified\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/api.js","lineNumber":2378,"sourceCode":"        throw new Error(\n          \"PDFWorker.create - the worker is being destroyed.\\n\" +\n            \"Please remember to await `PDFDocumentLoadingTask.destroy()`-calls.\"\n        );\n      }\n      return cachedPort;\n    }\n    return new PDFWorker(params);\n  }\n\n  /**\n   * The current `workerSrc`, when it exists.\n   * @type {string}\n   */\n  static get workerSrc() {\n    if (GlobalWorkerOptions.workerSrc) {\n      return GlobalWorkerOptions.workerSrc;\n    }\n    throw new Error('No \"GlobalWorkerOptions.workerSrc\" specified.');\n  }\n\n  static get #mainThreadWorkerMessageHandler() {\n    try {\n      return globalThis.pdfjsWorker?.WorkerMessageHandler || null;\n    } catch {\n      return null;\n    }\n  }\n\n  // Loads worker code into the main-thread.\n  static get _setupFakeWorkerGlobal() {\n    const loader = async () => {\n      if (this.#mainThreadWorkerMessageHandler) {\n        // The worker was already loaded using e.g. a `<script>` tag.\n        return this.#mainThreadWorkerMessageHandler;\n      }\n      const worker =","sourceCodeStart":2360,"sourceCodeEnd":2396,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/api.js#L2360-L2396","documentation":"A generic Error from the static PDFWorker.workerSrc getter: GlobalWorkerOptions.workerSrc is empty. The worker source URL is required to spawn the real Web Worker (the entry that contains the full pdf.js core). Without it the #initialize path cannot construct new Worker(workerSrc). The exception is not thrown if a workerPort is provided (which bypasses workerSrc) or if the fake/loopback worker path is used.","triggerScenarios":"Calling getDocument() without first assigning pdfjsLib.GlobalWorkerOptions.workerSrc, and without providing a worker/workerPort; bundler setups where the worker URL was tree-shaken or not copied; ES-module imports that forgot to set workerSrc.","commonSituations":"First-time integrations; webpack/vite configs that did not emit the worker bundle; CDN migrations that changed the path; SSR/Node usage without setting workerSrc or disabling the worker.","solutions":["Set pdfjsLib.GlobalWorkerOptions.workerSrc to the URL/path of pdf.worker.js (or .mjs) before calling getDocument.","When bundling, import the worker URL explicitly (e.g. workerSrc = new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url)).","Provide a workerPort via GlobalWorkerOptions.workerPort if you manage the Worker yourself.","For Node/SSR, set useWorkerFetch/disabled worker as appropriate."],"exampleFix":"// before\nimport * as pdfjsLib from 'pdfjs-dist';\npdfjsLib.getDocument({ url }); // throws: workerSrc not set\n\n// after\nimport * as pdfjsLib from 'pdfjs-dist';\npdfjsLib.GlobalWorkerOptions.workerSrc =\n  new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url).toString();\npdfjsLib.getDocument({ url });","handlingStrategy":"validation","validationCode":"if (!pdfjsLib.GlobalWorkerOptions.workerSrc && !pdfjsLib.GlobalWorkerOptions.workerPort) {\n  throw new Error('Set GlobalWorkerOptions.workerSrc before calling getDocument');\n}\npdfjsLib.GlobalWorkerOptions.workerSrc ||=\n  new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url).toString();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set GlobalWorkerOptions.workerSrc once at app boot, before any getDocument call.","With a bundler, derive workerSrc from new URL(..., import.meta.url) so the asset is emitted.","Provide GlobalWorkerOptions.workerPort if you construct the Worker yourself."],"tags":["configuration","worker","setup","workersrc"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}