Skip to content

pdf-import: use a file:// URL for the pdf.js worker (fixes jdf convert on Windows) - #16

Open
EienMosu wants to merge 1 commit into
uurtech:masterfrom
EienMosu:fix/pdf-import-worker-file-url
Open

EienMosu wants to merge 1 commit into
uurtech:masterfrom
EienMosu:fix/pdf-import-worker-file-url

Conversation

@EienMosu

@EienMosu EienMosu commented Oct 4, 2026

Copy link
Copy Markdown

Problem

On Windows every PDF conversion in the CLI fails before the first page:

Error: Setting up fake worker failed: "Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'".

pdf.js runs its fake worker on Node by import()ing GlobalWorkerOptions.workerSrc, and packages/jdf-pdf-import/src/node.ts sets it to the resolved absolute path. The published @uurtech/jdf-cli@0.2.9 bundles this package, so npx @uurtech/jdf-cli convert x.pdf fails the same way on Windows.

Fix

Pass pathToFileURL(workerPath).href instead of the bare path. Same code on every platform.

Verification

Windows (windows-latest, Node 22): https://github.com/EienMosu/jdf/actions/runs/37241435201

Case Result
npx @uurtech/jdf-cli@0.2.9 convert spec/examples/sample.pdf fails, Received protocol 'c:'
upstream master from source fails, Received protocol 'd:'
this branch 30 pages, jdf validate passes

The .jdf produced on Windows is byte-identical to the macOS one (sha256 a431d18f…aaa7b707).

macOS, before and after the change: spec/examples/sample.pdf output unchanged (same sha256), verify:regress 25 checked / 0 changed, verify:tables 120/120, verify:order 100%, pnpm typecheck green.

The same change was in the win branch (ed4622f) and was reverted in 2572af0 only to keep #5 scoped to the desktop app, so @rcpzen is co-author.

Side note, not part of this PR: on Node 18 and 20, jdf convert x.pdf fails earlier on every OS with Promise.withResolvers is not a function (pdfjs-dist 4.10 modern build), while tools/jdf-cli declares engines.node >= 18 and the README says Node 20+. Happy to send a separate PR (bump engines to >= 22, or a small polyfill), whichever you prefer.

…rt x.pdf` on Windows)

pdf.js runs its fake worker on Node by import()ing GlobalWorkerOptions.workerSrc.
We set it to the resolved absolute path, which Node's ESM loader rejects on
Windows ("Only URLs with a scheme in: file, data, and node are supported by
the default ESM loader. Received protocol 'd:'"), so every PDF conversion in
the CLI fails there, including the published @uurtech/jdf-cli bundle.

pathToFileURL() gives a file:// URL on every platform. On macOS the output of
spec/examples/sample.pdf is byte-identical before and after (same sha256),
and verify:regress (25 checked, 0 changed), verify:tables (120/120) and
verify:order (100%) stay green.

The same fix was part of the win branch (ed4622f) and was reverted in
2572af0 only to keep that PR scoped to the desktop app.

Co-authored-by: rcpzen <recepzen@hotmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant