{"record":{"id":"e6967fd78fd1e1f0","repo":"mozilla/pdf.js","slug":"jbig2-failed-to-initialize","errorCode":null,"errorMessage":"JBig2 failed to initialize","messagePattern":"JBig2 failed to initialize","errorType":"exception","errorClass":"Jbig2Error","httpStatus":null,"severity":"error","filePath":"src/core/jbig2_ccittFax.js","lineNumber":43,"sourceCode":"\nclass JBig2CCITTFaxImage extends WasmImage {\n  _filename = \"jbig2.wasm\";\n\n  _noWasmFilename = \"jbig2_nowasm_fallback.js\";\n\n  static get instance() {\n    return shadow(\n      this,\n      \"instance\",\n      new JBig2CCITTFaxImage(/* trackInstance = */ true)\n    );\n  }\n\n  async decode(bytes, width, height, globals, CCITTOptions) {\n    const module = await this._getModule(JBig2);\n\n    if (!module) {\n      throw new Jbig2Error(\"JBig2 failed to initialize\");\n    }\n    let ptr, globalsPtr;\n\n    try {\n      const size = bytes.length;\n      ptr = module._malloc(size);\n      module.writeArrayToMemory(bytes, ptr);\n\n      if (CCITTOptions) {\n        module._ccitt_decode(\n          ptr,\n          size,\n          width,\n          height,\n          CCITTOptions.K,\n          CCITTOptions.EndOfLine ? 1 : 0,\n          CCITTOptions.EncodedByteAlign ? 1 : 0,\n          CCITTOptions.BlackIs1 ? 1 : 0,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jbig2_ccittFax.js#L25-L61","documentation":"Thrown by JBig2CCITTFaxImage.decode when _getModule(JBig2) returns a falsy module, meaning neither the wasm build (jbig2.wasm) nor the JS fallback (jbig2_nowasm_fallback.js) could be loaded. JBIG2/CCITT decoding is entirely module-backed, so a missing module prevents any decoding.","triggerScenarios":"Decoding a JBIG2-encoded image or a CCITT Group 3/4 image while the jbig2.wasm asset cannot be fetched (wrong wasmUrl, 404, CSP block) AND the non-wasm fallback also failed to load. Reached via getDocument rendering any JBIG2 image.","commonSituations":"Deployments that omit the JBIG2 assets, set an incorrect wasmUrl, run under a CSP that blocks the worker/wasm fetch, or disable worker fetch. Also seen in Node.js usage where the fallback loader has no DOM.","solutions":["Provide a correct wasmUrl and ship jbig2.wasm alongside qcms_bg.wasm from pdfjs-dist.","Ensure useWorkerFetch:true is set on getDocument so the worker can resolve the module URL.","Adjust CSP to allow worker-src and wasm; serve .wasm as application/wasm.","If wasm is unavailable, ensure the non-wasm fallback JS file is reachable at the configured location."],"exampleFix":"// before\ngetDocument({ url });\n\n// after\ngetDocument({\n  url,\n  useWorkerFetch: true,\n  wasmUrl: '/pdfjs-dist/web/',  // contains jbig2.wasm\n});","handlingStrategy":"validation","validationCode":"// Validate the decoder asset configuration before loading:\nfunction jbig2Configured(opts) {\n  return !!(opts && opts.useWorkerFetch && opts.wasmUrl);\n}","typeGuard":"function hasDecoderAssetConfig(opts) {\n  return opts != null && opts.useWorkerFetch === true &&\n    typeof opts.wasmUrl === 'string' && opts.wasmUrl.length > 0;\n}","tryCatchPattern":"try { await page.render({ canvasContext }).promise; }\ncatch (err) {\n  if (err?.name === 'Jbig2Error' && /failed to initialize/.test(err.message)) {\n    console.warn('JBIG2 module unavailable; check wasmUrl/useWorkerFetch.');\n  } else throw err;\n}","preventionTips":["Ship jbig2.wasm and set useWorkerFetch:true plus wasmUrl in getDocument.","Allow worker-src and wasm in CSP; serve .wasm as application/wasm.","Confirm assets are reachable at the configured URL."],"tags":["pdf","jbig2","ccitt","wasm","config","decoder"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}