Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in FormData instead of form-data library #96

Closed
michaelhays opened this issue Mar 14, 2024 · 5 comments
Closed

Use built-in FormData instead of form-data library #96

michaelhays opened this issue Mar 14, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@michaelhays
Copy link

michaelhays commented Mar 14, 2024

Hey there, I'm trying to upload a file with client.uploads.uploadFile(), and am seeing the error:

Cannot find module 'form-data'

The error happens when calling eval('require')('form-data') here.

This is the same issue that I ran into with #54, so it seems that the eval('require')('<library>') approach still breaks with my configuration for some reason, whether that's due to Vercel, ESM vs CJS, or something else. (Note that I tried installing form-data to my package.json, to no avail.)

It's probably wise to figure out what is going on at the root here, but I think a good immediate solution would be to drop the form-data library in favor of just using the FormData that has been built-in to Node.js since v18.

This would require dropping support for Node.js 16, but that has been end-of-life since September 2023, so this seems like a reasonable time to do so. Plus, Node.js 16 could still work with the --experimental-fetch flag.

There are some other good reasons to drop form-data laid out in this issue: form-data/form-data#537

What do you think?

@lukaszsocha2
Copy link
Contributor

Hi @michaelhays,
thanks for reaching us. Let me talk about this one with the team and we'll get back to you.
Best,
@lukaszsocha2

@mhagmajer
Copy link
Contributor

Thanks! We are going to plan doing this.

@mhagmajer
Copy link
Contributor

Hi @michaelhays, we're already using FormData in browser environment

. Please feel free to reopen the issue as needed. Thanks for reaching out!

@michaelhays
Copy link
Author

Hi @mhagmajer, the problem on my end is actually the very next line:

: eval('require')('form-data');

The eval('require') approach doesn't work in a Vercel environment, as discussed in #54. That PR was fixed by simply removing the library, which wasn't necessary. In this case, you can do the same thing, since the form-data library is no longer needed as of Node.js 18, since FormData is now built in with Node.

Could you please re-open this issue? The only way I'm able to use this library right now is by patching it to remove the call to eval('require')('form-data').

@michaelhays
Copy link
Author

You can keep this closed in favor of #213, since I finally figured out the root issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants