-
Notifications
You must be signed in to change notification settings - Fork 548
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
Buffer.from
isn’t supported in all JavaScript runtimes
#444
Comments
Is there any progress with it? It seems during 1 month no one reacted on your issue as well as moved to btoa... |
I've made a pull request to add fix this in case Buffer doesn't exist #461 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The new
oauth.token
method usesBuffer.from
under the hood, butBuffer
is Node-specific and won’t work in other runtimes.The recommendations for other runtimes appear to be:
btoa
btoa
orstd/encoding/base64
btoa
btoa
In fact, WinterCG (the standards body governing alternative JS runtime interoperability) mandates
btoa
on the global scope for compliant runtimes (which is basically any edge runtime that’s not Node or Bun).The merits of using
btoa
are mixed. It’s not actually a deprecated API; it’s merely marked as legacy and the recommendation for modern code (especially when using Unicode, which we don’t) is to use something more compatible. If you have a single implementation with known inputs and you know it’s going to create the output correctly, it’s probably fine to usebtoa
.I recommend this package uses
btoa
instead ofBuffer.from().toString(“base64”)
, because it’s more compatible and doesn’t introduce that much of a footgun. The alternative would be to ponyfillbuffer
, or introduce a separate package just for base64 encoding/decoding; these would add more complexity and downstream dependencies so are probably less favourable.As always, will gladly PR this.
The text was updated successfully, but these errors were encountered: