Zilliqa / zilliqa-js

JavaScript SDK for Zilliqa blockchain
https://www.npmjs.com/package/@zilliqa-js/zilliqa
GNU General Public License v3.0
131 stars 74 forks source link

@zilliqa-js/crypto doesn't build with vite due to using require with elliptic signature #422

Closed hatzz closed 2 years ago

hatzz commented 2 years ago

Describe the bug We are using svelte kit to build a frontend that uses the zilliqa-js library. Svelte kit uses vite to build the website and has a common-js plugin which converts commonjs imports to esm but when you mix both require and ecmascript imports it cannot handle it. The error we get is require is not defined since the bundler does not convert the require to an import. I have tried multiple different ways to try and get vite/rollup to transform only this package without success.

To Reproduce

Go to this repo: https://github.com/Hatzz/zilliqa-js-sveltekit Clone it and follow the instructions in the README.md

Expected behavior

The zilliqa-js/crypto library should try to implement the elliptic package with an import instad of require

Additional context

I've read the code and see that this is needed due to the type declarations around elliptic but there must be some other workaround for this hopefully? Maybe it is possible to implement custom type declarations?