Error on the `wrangler/templates/middleware` directory

What is happening? I'm getting all this errors in the wrangler/templates/middleware and couldn't find any solution in the docs.
No description
6 Replies
arthur cosendey
arthur cosendeyOP8mo ago
After interacting with phind in my codebase appears to be a problem with the
facadeEvent
facadeEvent
, here's the response from phind: The error you're encountering in the wrangler file, specifically at line 228, is due to the incorrect usage of Promise.all with facadeEvent[facade_waitUntil]. The error message suggests that Promise is being treated as a value rather than a type, which is a common issue when dealing with TypeScript's strict typing system. Given the context and the error message, it seems like the problem arises because facadeEvent[facade_waitUntil] is expected to be an array of promises (Awaitable<unknown>[]), but TypeScript is interpreting it differently. This could be due to how the facade_waitUntil symbol is defined or used within the Facade_ExtendableEvent class. To resolve this issue, ensure that facadeEvent[facade_waitUntil] is correctly initialized as an array of promises before attempting to use Promise.all on it. Here's a revised approach to ensure that facadeEvent[facade_waitUntil] is properly handled: Ensure Proper Initialization: Make sure that facadeEvent[facade_waitUntil] is initialized as an empty array if no promises have been added yet. This ensures that Promise.all receives an array even if it's empty. Correct Usage of Promise.all: Ensure that Promise.all is used correctly. It expects an iterable of promises. If facadeEvent[facade_waitUntil] is not guaranteed to always contain promises, you should check its length before calling Promise.all. Here's a potential fix considering the above points:
// Inside the "__facade__originalAddEventListener__('scheduled', (event) => {...})" function

const facadeEvent = new __Facade_ScheduledEvent__("scheduled", {
scheduledTime: event.scheduledTime,
cron: event.cron,
noRetry: event.noRetry.bind(event),
});

__FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);

// Check if there are any promises to wait until completion
if (Array.isArray(facadeEvent[__facade_waitUntil__]) && facadeEvent[__facade_waitUntil__].length > 0) {
event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
}
// Inside the "__facade__originalAddEventListener__('scheduled', (event) => {...})" function

const facadeEvent = new __Facade_ScheduledEvent__("scheduled", {
scheduledTime: event.scheduledTime,
cron: event.cron,
noRetry: event.noRetry.bind(event),
});

__FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);

// Check if there are any promises to wait until completion
if (Array.isArray(facadeEvent[__facade_waitUntil__]) && facadeEvent[__facade_waitUntil__].length > 0) {
event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
}
This adjustment ensures that Promise.all is only called if there are actually promises to wait upon, addressing the TypeScript error about Promise being used as a value.
ChainFuse
ChainFuse8mo ago
arthur cosendey
arthur cosendeyOP8mo ago
@Community Champion @Cloudflare (Server Owner)
James
James8mo ago
?pings
Flare
Flare8mo ago
Please do not ping community members for non-moderation reasons. Doing so will not solve your issue faster and will make people less likely to want to help you.
arthur cosendey
arthur cosendeyOP8mo ago
sorry! hahaha i'm new here
Want results from more Discord servers?
Add your server