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

ESM module support #169

Open
JonasWijne opened this issue Nov 18, 2021 · 6 comments
Open

ESM module support #169

JonasWijne opened this issue Nov 18, 2021 · 6 comments

Comments

@JonasWijne
Copy link

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

@junderw
Copy link
Member

junderw commented Nov 18, 2021

Pull requests are welcome.

I have successfully created some hybrid packages like uint8array-tools.

@JonasWijne
Copy link
Author

made a repo where i reproduced the issue (https://github.com/jimbertools/vite-bip39), i looked at the problem for 2 days 🤣

@JonasWijne JonasWijne changed the title cant get this Compiled/transpiled with vite and ts Cant get this Compiled/transpiled with vite and ts Nov 18, 2021
@junderw
Copy link
Member

junderw commented Nov 18, 2021

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.

@JonasWijne
Copy link
Author

JonasWijne commented Nov 19, 2021

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

https://github.com/jimbertools/simple-bip39

@junderw junderw changed the title Cant get this Compiled/transpiled with vite and ts ESM module support Nov 19, 2021
@junderw junderw reopened this Nov 19, 2021
@junderw
Copy link
Member

junderw commented Nov 18, 2022

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.

@aulneau
Copy link

aulneau commented Nov 20, 2022

as i commented in #170, there is @scure/bip39 which works in all modern bundlers, is much lighter, and supports ESM

-> https://github.com/paulmillr/scure-bip39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants