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

[BUG] tweetnacl library causes bundling issues in various configurations #180

Closed
pospi opened this issue Mar 3, 2023 · 7 comments
Closed

Comments

@pospi
Copy link

pospi commented Mar 3, 2023

Describe the bug

This library is a very mature nodejs package (read: old & infrequently updated). Being in an older format can cause compatibility issues with more modern development environments and build tooling.

Presently it has become problematic in neighbour-hoods/applet-template#9 (comment). I wish I'd been tracking other times it has been an issue with bundlers, 'cos this is not the first time I've had to go into arcane Nodejs internals because of its presence in the stack.

Expected behavior

Developers shouldn't have to think about this module's compatibility with TypeScript, Rollup, Webpack, Web Dev Server, Babel, ESM modules or anything else. At least, not beyond the normal level of consideration that would apply to any other module being included in a project.

Could we try swapping it out for tweetnacl-ts or another alternative with broader module compatibility?

@jost-s
Copy link
Contributor

jost-s commented Mar 3, 2023

Hi @pospi, to reproduce this problem and test with a replacement, can I set up a rollup and web dev server project and use tweetnacl in it? tweetnacl-ts is even older, but it promises TS and bundler support. I want to test that before making a decision.

@pospi
Copy link
Author

pospi commented Mar 8, 2023

You should be able to, yeah- a WDS config similar to this one should reproduce (differently) the bug with or without the commonjs plugin active.

I don't know that tweetnacl-ts is such a great suggestion, either. I figure there are possibly other alternatives out there that cover the same signing functionality?

@jost-s
Copy link
Contributor

jost-s commented Apr 14, 2023

I can reproduce the problem, I believe. Running WDS with tweetnacl commonjs-rollup'd in the web-dev-server.config results in a "no default export in tweetnacl" error in the browser.
When changing the import of tweetnacl to import * as nacl from "tweetnacl", it succeeds, but the properties of nacl are not present. Some CommonJS weirdness, I suppose, that I don't fully get.

I'm looking for a replacement that is compatible with ES modules.

@jost-s
Copy link
Contributor

jost-s commented Apr 21, 2023

I've found a great replacement for tweetnacl and it works well: https://www.npmjs.com/package/@noble/ed25519
ESM compatible and works in browser and Nodejs.

When trying the client in WDS, isomorphic-ws is giving me grief. It's somewhat semi-CJS/ESM. I'm looking for a fix and will then release the client as WDS-compatible ;-)

@jost-s
Copy link
Contributor

jost-s commented Apr 24, 2023

I've chimed in on the commonjs issue in the WDS repo modernweb-dev/web#1700 (comment)

@jost-s
Copy link
Contributor

jost-s commented Apr 27, 2023

This has been a time-consuming endeavor, and it's still not working. I've submitted another issue with WDS because I can't even use ws with it. modernweb-dev/web#2248

@jost-s
Copy link
Contributor

jost-s commented May 1, 2023

v0.14.0 is released with the replaced NPM package. I'll open a new issue for WDS compatibility, even though the JS client can only wait for the WDS issues to be fixed.

@jost-s jost-s closed this as completed May 1, 2023
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