if there was the ability to specify a

if there was the ability to specify a main module config field for the main handler and the ability to add extra modules in the wrangler then that would prevent cloudflare:* module specifiers leaking to node in dev and allow cloudflare specific functionality to occur int its own build environment
17 Replies
Dario
Dario2mo ago
Oh, I see 🤔 That's an interesting idea, I would suggest you to maybe create a feature request in https://github.com/cloudflare/workers-sdk 🙂
GitHub
GitHub - cloudflare/workers-sdk: ⛅️ Home to Wrangler, the CLI f...
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - cloudflare/workers-sdk
Dario
Dario2mo ago
Do you have a specific use case?
KZ
KZOP2mo ago
yes so partial prerenderring in rrv7 breaks when you have a cloudflare: modules specifier with partial prerendering because the way most partial prerendering works in full stack frameworks is that the main module is resolved and loaded the one thing you can't get around with ES is that you can dynamic import a class
Dario
Dario2mo ago
rrv7 supports our vite plugin right? is the underlying issue caused by it incorrectly performing the prerendering in node? 🤔
KZ
KZOP2mo ago
i would put up a feature request but when i dug into it you actually had this feature early on for modules and then you deprecated i think no the vite-plugin "fixes" this issue by eating the writeBundle hook in rollup effectively killing it if i dive into the workerd it was enabled at one point and then you killed it,deprecated it.
Dario
Dario2mo ago
mh... I see....
KZ
KZOP2mo ago
or maybe not there's something call the new moduleregistry i think i'm misreading it but anyway it would be useful to be able to build modules separately so that if there isn't a reference to a cloudflare:* then you wouldn't have to shortcircuit vite
Dario
Dario2mo ago
in any case if the vite plugin is doing something to prevent rrv7 to do partial prerendering I would really recommend you to open an issue in https://github.com/cloudflare/workers-sdk, I am not super involved in the project these days but I'd definitely tag James Opstad who's the developer mainly working on it 😄
KZ
KZOP2mo ago
this isn't a vite-plugin issue i don't even use it because of that the one thing i can't get arround is that if i want a DO to exist in the same worker as my main code i have to deal with the fact that i can't get around module imports in the moduel
Dario
Dario2mo ago
yes maybe, but I think there are two different topics here: - the vite-plugin getting in the way of rrv7 - having an extra way to tell wrangler where to find DO classes the latter would allow workarounds for the former, but that wouldn't solve former as that would still be a bug (just a work-aroundable one) or am I missunderstanding? 🤔
KZ
KZOP2mo ago
no the only issue is that you can't define multiple modules. there's no way for the vite-plugin to fix it because this is how frameworks use vite
Dario
Dario2mo ago
there's no way for the vite-plugin to fix it because this is how frameworks use vite
But it's something that frameworks (leveraging the vite environments api) should fix, right? 🤔
KZ
KZOP2mo ago
no because regardless of anything if there is something in the main module there's no way of getting around the fact that the main module will be resolved in the node environment to render that route in build time
Dario
Dario2mo ago
I am not sure I follow, the main module is also run inside the vite ssr environment, isn't it?
KZ
KZOP2mo ago
yes prerendering or partial ssg however you want to think about it means that in the vite build step for the client you have to resolve and load the main module. and because an export class <DO> extends Durable... can't be done dynamically like the way you would await import('cloudflare:workers') it hast to get resolved and loaded if the main module didn't have a exported DO class then this would solve the problem. also likely nothing would change because the DO would still get bound and you'd pull into through the env
KZ
KZOP2mo ago
i think you are trying to solve it with this https://github.com/cloudflare/workerd/pull/1553
GitHub
Initial implementation of new jsg module registry by jasnell · Pul...
RM-17318 First step of the new module registry implementation (the jsg only bits). Expect several more follow up PRs. This PR provides the initial core of the new module registry implementation. It...
KZ
KZOP2mo ago
nm i'll follow up down the road just thought this would be an easy fix in wrangler

Did you find this page helpful?