TLDR: `new ReadableStream()` is working

TLDR: new ReadableStream() is working for me in normal workers, but not workers for platforms Hi guys! I'm implementing a feature using Prisma's Pulse product, which streams database change events to listening clients. I'm able to connect and listen to events perfectly on a traditional worker, but the same code on Workers for Platforms as a customer worker has issues when instantiating a ReadableStream.
Error: To use the new ReadableStream() constructor, enable the streams_enable_constructors compatibility flag. Refer to the docs for more information: https://developers.cloudflare.com/workers/platform/compatibility-dates/#compatibility-flags
I was hoping it would be as simple as: compatibility_flags = ['streams_enable_constructors'] When attempting to add this to my WFP wrangler.toml , I get the following error:
The compatibility flag streams_enable_constructors became the default as of 2022-11-30 so does not need to be specified anymore. [code: 10021]
Current compatibility date (for both platform code, and customer workers): compatibility_date = "2024-02-21" I'm guessing maybe I need to set this in my customer code somehow? Is there potentially some sort of binding I can set to enable this for my customers? My other suspicion is that it may be a different error, but cloudflare potentially catches it and throws this generic error instead.
3 Replies
ldp
ldpOP11mo ago
The code that is erroring can be found on this npm beta package Looks like you can't link directly to files on npm, but the line causing the error is at/dist/esm/PulseSubscription.workerd.js on line 87
function createWebSocketStream(webSocket, signal) {
return new ReadableStream({
// ...
function createWebSocketStream(webSocket, signal) {
return new ReadableStream({
// ...
kian
kian11mo ago
You need to set the compatibility date when uploading the customer Worker.
ldp
ldpOP10mo ago
Ok thanks a lot kian, this led me in the right direction! I was able to figure it out after some trial and error. I created a PR for the WFP documentation here , not really sure how I would have known about the ability to configure this without guessing. Imo, it would be a bit more intuitive if the user workers inherited the compatibility_date from the WFP project's wrangler.toml, if it's not explicitly set when uploading the user worker can you explain a bit more? not sure i understand how that's the case. as someone using the system, personally i find it really unintuitive. if you required an explicit compatibility_date with every user worker upload, then i would understand the thought process, but right now the compatibility_date on user workers is totally optional, as far as i can tell (not sure though bc of lack of documentation). it's already using a hidden default for user workers, i'm assuming? i didn't set one previously and they were working, just with different available functionality. i'm just proposing that if there is a hidden default anyway, it should prob be the same one as the wfp codebase to avoid that confusion in the future. or just require that compatibility_date is set with every user worker upload. makes a lot of sense! thanks for the example this makes it even more surprising that compatibility_date isn't required when uploading user workers though
Want results from more Discord servers?
Add your server