{"record":{"id":"f9e83ea9dbbf16a2","repo":"parallax/jsPDF","slug":"unable-to-load-file-url","errorCode":null,"errorMessage":"Unable to load file ${url}","messagePattern":"Unable to load file (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"builder.html","lineNumber":150,"sourceCode":"\t\t\tform.submit(function( event ) {\n\t\t\t  var formValues = form.serializeArray();\n\t\t\t  formValues = formValues.filter(function(item) {\n\t\t\t\treturn (item.name !== 'all');\n\t\t\t  });\n\t\t\t  build ( formValues );\n\t\t\t  event.preventDefault();\n\t\t\t});\n        });\n\t\t\n\t\tfunction loadBinaryResource (url, unicodeCleanUp) {\n\t\t  var req = new XMLHttpRequest()\n\t\t  req.open('GET', url, false)\n\t\t   // XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]\n\t\t  req.overrideMimeType('text\\/plain; charset=x-user-defined');\n\t\t  try {\n\t\t  req.send(null)\n\t\t  if (req.status !== 200) {\n\t\t\tthrow new Error('Unable to load file ' + url);\n\t\t  }\n\t\t  } catch (e) {\n\t\t  alert(e);\n\t\t  }\n\n\t\t  var responseText = req.responseText;\n\t\t  var StringFromCharCode = String.fromCharCode;\n\t\t  if (unicodeCleanUp === true) {    \n\t\t\tvar i = 0;\n\t\t\tfor (i = 0; i < responseText.length; i += 1) {\n\t\t\t  byteArray.push(StringFromCharCode(responseText.charCodeAt(i) & 0xff))\n\t\t\t}\n\t\t\treturn byteArray.join(\"\");\n\t\t  }\n\t\t  return req.responseText;\n\t\t}\n\n\t\tfunction uniq(a) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/builder.html#L132-L168","documentation":"This lives in builder.html, the jsPDF web-based module builder. loadBinaryResource performs a synchronous XMLHttpRequest (req.open('GET', url, false)) with the MIME overridden to 'text/plain; charset=x-user-defined' so binary bytes survive as a string. After req.send, if req.status !== 200 it throws 'Unable to load file <url>'. Because the throw is caught locally and only alert(e)'d, execution then falls through to req.responseText (empty/garbage), so a failed load both alerts and silently corrupts the build. Note that file:// and CORS failures yield status 0, which is also !== 200 and triggers the throw.","triggerScenarios":"Opening builder.html directly via the file:// protocol (modern browsers block synchronous local XHR -> status 0); a selected module's source file is missing (404); the dev server returns 500 or a redirect; the base path/folder structure changed; mixed-content or CORS blocking on the request.","commonSituations":"Double-clicking builder.html to open it locally instead of serving it over HTTP; running the builder after renaming/removing a source module that is still checked; pointing at a folder layout that no longer matches configuration; a stale dev server returning errors for a path.","solutions":["Serve the project over HTTP instead of opening the file directly: e.g. `python3 -m http.server` or `npx serve`, then open http://localhost:PORT/builder.html.","Open the browser Network tab and confirm the failing URL; fix the path or restore the missing file.","Deselect (uncheck) the module whose file cannot be found, or update configuration to the correct folder.","If a custom dev server returns non-200 for valid files, fix its routing/static mapping before rebuilding."],"exampleFix":"# before\n# open builder.html via file:///home/me/repo/builder.html   -> XHR status 0 -> throws\n\n# after\npython3 -m http.server 8000\n# then visit http://localhost:8000/builder.html","handlingStrategy":"validation","validationCode":"function ensureServable() {\n  if (/^file:/i.test(globalThis.location.protocol)) {\n    throw new Error('builder.html must be served over http(s), not opened via file://. Run: python3 -m http.server');\n  }\n}\nfunction probeUrl(url) {\n  var x = new XMLHttpRequest(); x.open('HEAD', url, false); x.send(null);\n  return x.status === 200;\n}\n// before building: ensureServable(); if (!probeUrl(fileUrl)) { /* skip/fix this module */ }","typeGuard":null,"tryCatchPattern":"try {\n  var data = loadBinaryResource(url, true);\n  if (!data) throw new Error('Empty response for ' + url);\n} catch (e) {\n  console.error('Build stopped: could not load', url, '-', e.message);\n  // do NOT fall through to use req.responseText; surface the failure to the user and abort the build.\n  throw e;\n}","preventionTips":["Always serve the repo over HTTP (python3 -m http.server / npx serve) — never open builder.html via file://.","Keep the source module folder structure intact with what configuration expects.","Watch the Network tab for 404/500/0-status responses when selecting modules.","Treat a non-200 load as fatal and abort the build rather than alerting and continuing with empty text."],"tags":["network","xhr","builder","file-loading","http","configuration"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}