How to use new FormData constructor in Deno server, I want to use it for my supabase edge function.
I've created an edge function in supabase that requires formdata,I know it's a browser side thing and also supports in latest node version. But when I use this in deno , such as
it gives an error after deployment , it says require is not defined.
But if I use
it also throws an error .
2 Replies
In Deno, you don't need to use
require
as it is a Node.js-specific module loading system. Deno uses ES modules, and you can use the FormData
API directly because it is a web standard API that Deno supports out of the box.
Here's how you can use FormData
in Deno:
If you're seeing an error when using const formData = new FormData();
, it's important to ensure that you're running your code in an environment where the FormData
constructor is available. In Deno, FormData
should be globally available, just like in the browser.
Make sure that you are using the correct Deno runtime environment that supports the FormData
API. If you're deploying to Supabase Edge Functions, you should check their documentation to ensure that they support the same web APIs as Deno does.
If you continue to encounter errors, please provide the exact error message, and I can help you debug further. Remember to check your Deno version as well, as older versions might not have the same level of web API support as the latest versions. 🦕I think you will have better answers if you ask Supabase folks