Jawad
Jawad2mo ago

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
const formData = require(form-data)
const formData = require(form-data)
it gives an error after deployment , it says require is not defined. But if I use
const formData = new FormData()
const formData = new FormData()
it also throws an error .
2 Replies
Deno AI Helper
Deno AI Helper2mo ago
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:
const formData = new FormData();
formData.append("key", "value");
// Add more key-value pairs or files as needed
const formData = new FormData();
formData.append("key", "value");
// Add more key-value pairs or files as needed
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. 🦕
Leokuma
Leokuma2mo ago
I think you will have better answers if you ask Supabase folks