Providing external dependencies to Worker Loader modules

Is there a way to pass through external dependencies (from node_modules) to a dynamic Worker's modules? for example:
import mod from "@happy-dom/global-registrator";

const worker = env.LOADER.get(renderId, () => {
return {
compatibilityDate: "2025-09-21",
compatibilityFlags: ["nodejs_compat"],
mainModule: "render.js",
modules: {
"render.js": `
import {WorkerEntrypoint} from "cloudflare:workers";
import {GlobalRegistrator} from "@happy-dom/global-registrator";

export class RenderEntrypoint extends WorkerEntrypoint {
async render() {
GlobalRegistrator.register();

// do something with document assigned to globalThis

await GlobalRegistrator.unregister();

return;
}
}`,
"@happy-dom/global-registrator": mod // how am I supposed to pass in the module here?
},
globalOutbound: null
};
});

const entrypoint = worker.getEntrypoint("RenderEntrypoint");
const result = await entrypoint.render();
import mod from "@happy-dom/global-registrator";

const worker = env.LOADER.get(renderId, () => {
return {
compatibilityDate: "2025-09-21",
compatibilityFlags: ["nodejs_compat"],
mainModule: "render.js",
modules: {
"render.js": `
import {WorkerEntrypoint} from "cloudflare:workers";
import {GlobalRegistrator} from "@happy-dom/global-registrator";

export class RenderEntrypoint extends WorkerEntrypoint {
async render() {
GlobalRegistrator.register();

// do something with document assigned to globalThis

await GlobalRegistrator.unregister();

return;
}
}`,
"@happy-dom/global-registrator": mod // how am I supposed to pass in the module here?
},
globalOutbound: null
};
});

const entrypoint = worker.getEntrypoint("RenderEntrypoint");
const result = await entrypoint.render();
3 Replies
Hard@Work
Hard@Work5d ago
I would guess you would need to bundle it in?
Isaac McFadyen
See the previous answer here: https://canary.discord.com/channels/595317990191398933/1421508601524260894/1421959845019385886 TLDR: yes you need to bundle yourself if you want it
cubeghost
cubeghostOP5d ago
gotcha, thanks!

Did you find this page helpful?