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

any plan to publish es module ? #86

Open
wighawag opened this issue Oct 25, 2024 · 6 comments
Open

any plan to publish es module ? #86

wighawag opened this issue Oct 25, 2024 · 6 comments

Comments

@wighawag
Copy link

Getting issues with modern tooling that expect es modules
Not sure yet what is the exact issue but feel like there is no reason why drand-client could not publish es-module, which brings further davantage like proper dead code elimination, etc...

@CluEleSsUK
Copy link
Contributor

I was actually banging my head against the wall on a different lib today wrt esmodules.
The crux is that esm can handle commonjs, but commonjs can't handle esm. Is there a specific tool you're having problems with?
I agree that esm is superior in every other way, but it's a jimmie rustler that support is still quite rubbish. We could possibly just compile everything to .mjs which should work on any reasonable node version?

@wighawag
Copy link
Author

wighawag commented Oct 25, 2024

Yes, you could compile to both and set the correct export

The issue I have is with cloudflare worker vitest integration. I have this error : cloudflare/workers-sdk#5367 but with tlock-js / drand-client

Error: Module cannot be synchronously required while it is being instantiated or evaluated. This error typically means that a CommonJS or NodeJS-Compat type module has a circular dependency on itself, and that a synchronous require() is being called while the module is being loaded.
 ❯ home/wighawag/dev/github.com/wighawag/fuzd/node_modules/.pnpm/[email protected]/node_modules/drand-client/http-caching-chain.js?mf_vitest_no_cjs_esm_shim:4:17
 ❯ home/wighawag/dev/github.com/wighawag/fuzd/node_modules/.pnpm/[email protected]/node_modules/drand-client/index.js?mf_vitest_no_cjs_esm_shim:7:46
 ❯ home/wighawag/dev/github.com/wighawag/fuzd/node_modules/.pnpm/[email protected]/node_modules/tlock-js/index.js?mf_vitest_no_cjs_esm_shim:4:24

@wighawag
Copy link
Author

@CluEleSsUK I made a reproduction repo : https://github.com/bug-reproduction/tlock-js-cf-worker-vitest

to see the bug

pnpm i
pnpm test

but it works when running the worker itself:

pnpm dev
# navigate to http://localhost:8787/roundAt/1729873909000

@wighawag
Copy link
Author

The same repo work with these modif:

drand-client: generate both cjs and esm: #87

tlock-js: generate both cjs and esm: drand/tlock-js#46

@wighawag
Copy link
Author

So the 2 PR works quite well. The only thing I noticed in that when using the es module in node, it output a performance warning because of not having {"type":" module"}

Ideally the project would have "type": "module" in package.json and tsconfig set to have "moduleResolution": "NodeNext" but that cause issue with your code (you also need to use .js extension for relative import)

The best in the future might be generate 2 packages: one esm and one cjs from the same code

But for now these 2 PR are probably better than what is there.

@wighawag
Copy link
Author

wighawag commented Nov 4, 2024

After testing in more scenarios, the solution proposed in my PR is still problematic

So I think the best way forward is to update the code to modern output and have a cjs build too

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

2 participants