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

Add es2020 esbuild target #2220

Closed
bgins opened this issue Aug 16, 2021 · 5 comments
Closed

Add es2020 esbuild target #2220

bgins opened this issue Aug 16, 2021 · 5 comments
Labels
adapters - general Support for functionality general to all adapters feature / enhancement New feature or request

Comments

@bgins
Copy link

bgins commented Aug 16, 2021

Describe the problem

SvelteKit cannot build code that uses big integer literals.

Big integer literals are an es2020 feature. Because of their design, they cannot be transpiled or polyfilled. Google's JSBI was written to address this with an option for forwards compatibility. From their README

To use BigInts in code that you want to run everywhere, you need a library. But there’s a difficulty: the BigInt proposal changes the behavior of operators (like +, >=, etc.) to work on BigInts. These changes are impossible to polyfill directly; and they are also making it infeasible (in most cases) to transpile BigInt code to fallback code using Babel or similar tools. The reason is that such a transpilation would have to replace every single operator in the program with a call to some function that performs type checks on its inputs, which would incur an unacceptable performance penalty.

Esbuild cites similar reasons for leaving big integer literals untouched

BigInts are not lowered to older syntax in esbuild because there is no direct translation. The BigInt specification decided to use normal JavaScript operators for BigInts and the JavaScript language does not have user-pluggable operator overloading. Code wanting to use BigInts on older browsers will have to be rewritten to use a library that uses function calls instead of native JavaScript operators.

In cases where a developer is authoring the code, it is possible use JSBI or an alternative. But libraries have started using the big integer literal syntax directly, and it is not possible to use these libraries with SvelteKit today. One example library is noble-ed25519, a top quality cryptography library.

Describe the proposed solution

I would like to see an option to set the esbuild target to es2020 with SvelteKit.

Reading through existing issues, changing SvelteKit to only target es2020 would be problematic for node 12 (see discussion in #1667).

One possibility would be a configurable build target. It may be possible to do this already when using adapter-node:

esbuild: esbuildConfig

A more general solution would be preferable, but my use case involves adapter-static and I would love to see an option there if this can be solved in the adapters.

Alternatives considered

Avoid libraries that use big integer literals. This would hopefully be a temporary solution. More libraries are likely to use big integer literals going forward, and the noble libraries that use them today are particularly high quality.

Importance

would make my life easier

Additional Information

No response

@kotx
Copy link

kotx commented Aug 23, 2021

I'm also getting this issue with js-ipfs. Any workaround currently?
Edit: seems like this config in the kit section of svelte.config.js works for now:

vite: () => ({
    build: {
        target: [ 'es2020' ]
    }
})

@ignatiusmb
Copy link
Member

I believe esbuild options can now be configured for all adapters except static, can you try and see if it works with adapter-node and prerendering the pages with big integers?

@kotx
Copy link

kotx commented Aug 23, 2021

I believe esbuild options can now be configured for all adapters except static, can you try and see if it works with adapter-node and prerendering the pages with big integers?

Seems to work as long as the target option is specified like above. I didn't need anything other than default settings for adapter-node. It also works with adapter-static without additional config.

@bgins
Copy link
Author

bgins commented Aug 23, 2021

I believe esbuild options can now be configured for all adapters except static, can you try and see if it works with adapter-node and prerendering the pages with big integers?

This works for me now, both with adapter-node and prerendering and also with adapter-static.

Thank you for adding this. Much appreciated! 🙏

@ignatiusmb ignatiusmb added adapters - general Support for functionality general to all adapters feature / enhancement New feature or request labels Aug 24, 2021
@ignatiusmb
Copy link
Member

Thanks for the confirmation. I take it that it has been resolved now, so I'll be closing this.

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

No branches or pull requests

3 participants