ESM module support
Opened this issue · 6 comments
main.ts
import { wordlists } from 'bip39';
console.log(wordlists['EN']);
i get multiple issues, since thisa is cjs, could this be made to work with esm
Pull requests are welcome.
I have successfully created some hybrid packages like uint8array-tools.
made a repo where i reproduced the issue (https://github.com/jimbertools/vite-bip39), i looked at the problem for 2 days 🤣
Memo for possible solutions:
- Something like this commit might be helpful. re: wasm_path.ts vs. wasm_path_cjs.ts but this only forks the path logic.
- ESM would use import meta object and cjs use path join with __dirname... however readFileSync is a node-only concept, and not sure how bundlers would handle it... the above repo forks the browser / node logic further by just importing the wasm directly (webpack is able to understand this, and browsers too)...
- JSON modules are one way to do it. Chrome 91 contains support for json ESM modules. Another way would be to use fetch in the browser... but I am not sure how bundlers would support it.
- An alternative would be to move away from json and convert the JSON files to files that export as default the JSON contents (by using sed during build step etc.)
- This is problematic for people who want to exclude wordlists from their bundle. You would require a bundler with tree shaking.
- An alternative would be to move away from json and convert the JSON files to files that export as default the JSON contents (by using sed during build step etc.)
we made a simple ts lib with only what we needed, in the future we will make this feature parity with this lib and make a pull request or something
I have a fork for this: https://github.com/nahoc10/bip39-esm-support
Pull requests welcome, but it seems like your fork completely breaks everything with no attempt to try and maintain compatibility via a hybrid model etc.
Also, you are violating the terms of the ISC license:
provided that the above copyright notice and this permission notice appear in all copies.
You have completely removed the Copyright notice and the permission notice.