-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Hi everyone,
I’m trying to create a Cloudflare Worker that uses MuPDF for PDF transformations. However, I’m running into some issues when trying to import and use the MuPDF library. Here’s what I’ve tried so far:
Using import
:
import { Document } from "mupdf";
This results in the following error:
Uncaught Error: not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)
Using require
:
const mupdf = require("mupdf");
This results in the following error:
✘ [ERROR] This require call is not allowed because the imported file "node_modules/mupdf/dist/mupdf.js" contains a top-level await
The top-level await in "node_modules/mupdf/dist/mupdf.js" is here:
node_modules/mupdf/dist/mupdf.js:24:17:
24 │ const libmupdf = await libmupdf_wasm();
Questions:
- Is it possible to use MuPDF in a Cloudflare Worker? If so, how can I properly import and use it?
- Are there any specific configurations or build steps I need to follow to make MuPDF work in this environment?
- Are there any alternative libraries or approaches you would recommend for PDF transformations in a Cloudflare Worker?
Additional Context:
- I’m using the latest version of MuPDF.
- My Cloudflare Worker is set up with Wrangler.
- I’m relatively new to Cloudflare Workers and working with WASM in this context.
Any help or guidance would be greatly appreciated! Thank you in advance.
Steps to Reproduce:
- Set up a new Cloudflare Worker project using Wrangler.
- Install MuPDF using npm:
npm install mupdf
- Attempt to import MuPDF in the worker script using either
import
orrequire
.
defidefi5 and adarshmadrecha
Metadata
Metadata
Assignees
Labels
No labels