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.
6 Replies
After interacting with phind in my codebase appears to be a problem with the , 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:
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.
@Community Champion @Cloudflare (Server Owner)
?pings
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.
sorry! hahaha i'm new here