Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Uses of BigInt over the project breaks compatibility w/ ES5 (?) #871

Closed
Suero152 opened this issue May 14, 2024 · 3 comments
Closed

Uses of BigInt over the project breaks compatibility w/ ES5 (?) #871

Suero152 opened this issue May 14, 2024 · 3 comments

Comments

@Suero152
Copy link

I was having some problems while trying to use the Babel transpiler with Typebox modules because it makes use of BigInts which are not supported in older vesions of JS and Babel can't transpile them, so I wasn't being able to run the code on a ES5 JS VM with Nakama.

The solution I was able to get it working was to patch (with git patches and patch-package) the library and remove the uses of BigInt on the modules I was importing. ( Like typebox/value/hash that uses BigInts )

Another solution (as stated in https://babeljs.io/docs/babel-plugin-syntax-bigint) would be to make use of the JSBI library in Typebox and eventually run babel-plugin-transform-jsbi-to-bigint to codemod it to BigInt in the future.

I'm creating this issue because someone can get into an similar problem and this may be useful somehow, also I wanted to know if my current approach is correct or it wasn't needed.

The patch I used to remove some BigInt usages: https://gist.github.com/Suero152/7508faa894f12477a5c2fec7d3a974da

@Suero152 Suero152 changed the title Uses of BigInt over the project breaks compatibility (?) Uses of BigInt over the project breaks compatibility w/ ES5 (?) May 14, 2024
@sinclairzx81
Copy link
Owner

@Suero152 Hi, Thanks for posting this,

The minimum ES target for TypeBox is ES2020 (so does expect the runtime to have support for the BigInt type) Note though that TypeBox doesn't use the BigInt literal syntax internally as some users have experienced issues transforming the 1000n suffix. From this it might be possible to polyfill the globalThis.BigInt constructor only (this might be easier than trying to patch for the syntax)

Unfortunately, I'm not familiar with the Nakama runtime or babel transform plugins so can't provide much assistance here, but do appreciate having links and references submitted for the benefit of other users. In terms of your outlined approach, I guess it's fine if it works :)

Would you like me to convert this issue into a discussion?

@Suero152
Copy link
Author

@Suero152 Hi, Thanks for posting this,

The minimum ES target for TypeBox is ES2020 (so does expect the runtime to have support for the BigInt type) Note though that TypeBox doesn't use the BigInt literal syntax internally as some users have experienced issues transforming the 1000n suffix. From this it might be possible to polyfill the globalThis.BigInt constructor only (this might be easier than trying to patch for the syntax)

Unfortunately, I'm not familiar with the Nakama runtime or babel transform plugins so can't provide much assistance here, but do appreciate having links and references submitted for the benefit of other users. In terms of your outlined approach, I guess it's fine if it works :)

Would you like me to convert this issue into a discussion?

Thanks for the speedy response, yeah you can convert into a discussion if you want, tysm for supporting this amazing lib

@sinclairzx81
Copy link
Owner

@Suero152 Hey, all good :) Will move to the issue into discussions

Repository owner locked and limited conversation to collaborators May 16, 2024
@sinclairzx81 sinclairzx81 converted this issue into discussion #873 May 16, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants