Skip to content

Can't run in bun/deno #396

@eric-burel

Description

@eric-burel

Hi,

I am opening this issue to have a cleaner discussion, but I am facing an issue to similar the one observed earlier in Electron : #68. Last comments in this related discussion are mentioning the same error in Deno and Bun, though maybe for other reasons.

It seems that we need to either disable a worker, or setup one, but I couldn't find a solution.

The following code is supposed to set a worker (or disable it), but sadly you can't load pdfjs-dist in a bun script is it will raison an error on 7501 | const SCALE_MATRIX = new DOMMatrix(); because DOMMatrix is not defined.

const pdfjs = await import('pdfjs-dist/build/pdf');
pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');
pdfjs.GlobalWorkerOptions..workerSrc = pdfjsWorker;
// Doesn't work either
// pdfjs.GlobalWorkerOptions.disableWorker = true

Related links:
mozilla/pdf.js#10478
https://www.npmjs.com/package/pdfjs-dist

The best option is probably to disable the worker, but I couldn't find an alternative syntax yet. Will update if I do.

Update 1: I've hacked my way to the built source and if after the line we.PDFJS.pdfBug = !1; I add we.PDFJS.disableWorker = true;, I can go beyond this issue.

The problem is that the PDFJS object is defined in a pdfjs-code file that is not part of the source, but is built by rollup. It is then imported here. I guess we could somehow detect a bun/deno environment at this point and disable the worker from there, or use an environment variable or whatever.

Update 2: it seems that unmerged PR #384 was trying to fix that but also considers another unrelated bug.
For reference, you can explicitly detect Bun and Deno environments by checking if Bun and Deno global variables are undefined. But perhaps the worker should be disabled whenever we are in a server environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions