How to use node_compat = true with cloudflare pages ?

I know that there is a flag nodejs_compat, but it's not as powerful as node_compat = true , nice nodejs_compat isn't gonna polyfill modules such as fs or os How could I use node_compat = true with a cloudflare pages (not worker) project ? Can I do it directly with the cloudflare UI/Dashboard ?
9 Replies
James
James17mo ago
I don't believe that you can today, at least not easily. You could maybe build your own _worker.js with it... but it's not going to be straightforward since this is done at build time.
abc222
abc22217mo ago
Yes, building my own "_worker.js" would be pretty hard since I use a front-end framework (SvelteKit) however, the module I use for postgres needs those node.js modules : https://github.com/porsager/postgres/tree/cloudflare Is that something that they should fix on their own side ?
GitHub
GitHub - porsager/postgres at cloudflare
Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno - GitHub - porsager/postgres at cloudflare
abc222
abc22217mo ago
https://github.com/porsager/postgres/pull/599 He commited something that is supported by Cloudflare Workers (with node_compat = true), but if it's only supported with a legacy flag that isn't working with nodejs_compat (the new flag), is it a real support ? And do you think that it would be possible for him to have something working with nodejs_compat instead of node_compat = true ?
GitHub
Support for Cloudflare Workers by porsager · Pull Request #599 · po...
Initial support for using Postgres.js in Cloudflare Workers (tcp support was just released today).
James
James17mo ago
Ideally it wouldn't require node_compat, yeah. Or even nodejs_compat. But that's going to be quite difficult. A better short-term approach might be to convince wrangler pages to support the older node_compat polyfills to better support these kind of libraries. You might open an issue on the workers-sdk repo about this if there's not one already.
abc222
abc22217mo ago
So I should open an issue on workers-sdk ? I can try but if it's an older flag, maybe they are looking to deprecate it somehow I'll also contact the SQL driver's module to check with him if it would be easy to reach a higher level of compatibility
James
James17mo ago
I'd open a discussion about it at least, yeah - supporting it in pages command should be pretty easy, and if it unblocks using libraries like this, it seems like a good idea to me.
abc222
abc22217mo ago
Yes, I made a suggestion, but since my projects deploys with GitHub, it would also be great to have it working with cloudflare's web UI
deanmauro
deanmauro17mo ago
I had the same question. CF hasn't added postgres support in Pages yet unless we add the polyfills ourselves https://discord.com/channels/595317990191398933/1113898845244489818
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server