paulmillr / noble-secp256k1

Fastest 4KB JS implementation of secp256k1 signatures and ECDH
https://paulmillr.com/noble
MIT License
757 stars 114 forks source link

unpkg.com browser Error: Uncaught RefereceError: exports is not defined #75

Closed cmdruid closed 1 year ago

cmdruid commented 1 year ago
secp256k1@1.7.0:3 Uncaught ReferenceError: exports is not defined
    at secp256k1@1.7.0:3:23
(anonymous) @ secp256k1@1.7.0:3

Hello. I am getting this error when trying to import the library into the browser, from the following URL: https://unpkg.com/@noble/secp256k1@1.7.0

I do not get this problem when I import the file from the github releases page, or locally from my machine.

I think there may be a mis-configuration somewhere (package.json?), as unpkg.com is not properly hosting a browser version of the file , even though it seems to work fine when I import the file from other sources.

This is not a critical issue. I thought to bring it up since unpkg.com is useful as a CDN, and it would be nice to pull a working version from there.

paulmillr commented 1 year ago

You should report this to unpkg. I am not familiar with their build system, it could be their error.

We support deno, webpack, browserify, rollup, standalone file, etc -- hard to ensure everything works properly.

cmdruid commented 1 year ago

unpkg.com is run by npmjs.com and is their automated CDN service.

NPM supports a "unpkg" keyword in package.json to point towards a browser-compatible build. It tells NPM specifically which file in your package to make available on their unpkg CDN.

I think something like "unpkg": "lib/index.js" would work as an example. If you have any questions about it, please let me know!

I do not mean to make a big deal out of it, just I would like to import using unpkg.com/@noble/libsecp256k1 versus github.com/paulmillr/noble-secp256k1/releases/download/1.7.0/noble-secp256k1.js (also not deal with CORS issues from github imports). Thank you for responding!

paulmillr commented 1 year ago

I can change package.json, but did you actually test the change? I don't want to do a broken release

cmdruid commented 1 year ago

I did a test deployment and submitted a PR. No need to merge, just demonstrating the minor changes to get it working with NPM's unpkg CDN. See here:

https://github.com/paulmillr/noble-secp256k1/pull/76

paulmillr commented 1 year ago

v2.0 will be unpkg-friendly