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

Remove node-fetch and other dependencies from typescript sdk #5468

Open
remorses opened this issue Dec 21, 2024 · 2 comments · May be fixed by #5476
Open

Remove node-fetch and other dependencies from typescript sdk #5468

remorses opened this issue Dec 21, 2024 · 2 comments · May be fixed by #5476
Assignees
Labels
dependencies Pull requests that update a dependency file feature Requests for new features. product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages

Comments

@remorses
Copy link

remorses commented Dec 21, 2024

Feature Description

Currently even the fernapi/fern-typescript-browser-sdk generator import node-fetch and form-data, this code will fail to build in tools like Vite, because the bundler tries to import Node.js specific libraries and it fails.

Please remove node-fetch which is no longer needed, since in Node.js 18 fetch and FormData are already globals.

Here is the full list of packages you can remove:

  • qs: you can inline a simple function instead of qs.stringify, should be very simple
  • node-fetch: fetch is already available everywhere
  • form-data and formdata-node: FormData is already available everywhere, use that instead
  • form-data-encoder: you can do this instead
    new Response(formData, { headers: {'content-type': 'multipart/form' }}).text()
  • js-base64: atob and btoa are available everywhere
@remorses remorses added feature Requests for new features. product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages labels Dec 21, 2024
@dannysheridan
Copy link
Member

👋 hey @remorses, I'd recommend using fernapi/fern-typescript-node-sdk instead of fernapi/fern-typescript-browser-sdk as our TypeScript generator is universal and can run in popular runtimes including the browser, Node.js, Bun, Lambda, Cloudflare Worker, and Deno.

Looping in @Swimburger who has been working on the TypeScript generator.

Out of curiosity, would you be interested in contributing this improvement if we agreed on an approach and pointed you toward the right files in the repo?

@dannysheridan dannysheridan added the dependencies Pull requests that update a dependency file label Dec 21, 2024
@remorses
Copy link
Author

Thank you, the node generator is much better, it only depends on qs, url-join, stream and js-base64, all of them could be easily replaced to remove the dependencies.

It still does a dynamic import of node-fetch, to be able to use it in Vite without a Node polyfill I had to mark it as external, which is not great experience for the end user.

I can work on a PR, I would love to collaborate with you, Fern is awesome!

@remorses remorses linked a pull request Dec 24, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file feature Requests for new features. product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages
Development

Successfully merging a pull request may close this issue.

3 participants