-
Notifications
You must be signed in to change notification settings - Fork 29
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
v1.9.0 stopped working with vitejs (rollup) #168
Comments
Looking a bit deeper I found this commit which in As the depencney is via an url, I guess the |
@jonaskello From your description above, I don't think you are picking the esm version of the library, as you are showing modules etc.
about line 6264
|
Yes it does seem to have something to do with a global version of nkeys. However I'm not sure why 1.8.1 works and 1.9.0 does not, leaving all other things equal. Did the way the esm module is exposed change between these versions? Here is a small bash script that reproduces the error. It will create a small project, bundle it with npm init -y
npm install --save vite nats.ws
npm install --save-dev serve
cat<<EOF>./index.html
<script type="module" src="index.js"></script>
EOF
cat<<EOF>./index.js
import { connect } from "nats.ws";
console.log("Hello");
EOF
npx vite build
cd dist
npx serve
cd .. |
If you look at the sources generated by vite, the full source code is about 30,194 bytes or so.
|
I'm seeing the same error when importing nats.ws into a MeteorJS codebase. Tracing the source of (function(nacl) {
... // Jump to the end of the function at line 5940)
})(typeof module !== 'undefined' && module.exports ? module.exports : globalThis.nacl = globalThis.nacl || {});
const nacl = globalThis.nacl; Reviewing the ternary clause (above) that determines what to pass as const nacl = globalThis.nacl; And the first attempt to work with nacl on line 5943 results in const nacl = globalThis.nacl; // globalThis.nacl isn't defined when module.exports is defined
const denoHelper = {
fromSeed: nacl.sign.keyPair.fromSeed, // nacl is undefined because it was written into module.exports, not globalThis.nacl
sign: nacl.sign.detached,
verify: nacl.sign.detached.verify,
randomBytes: nacl.randomBytes
}; I believe the fix is for the nacl assignment to mirror the ternary condition. So line 5941 would become: const nacl = typeof module !== 'undefined' && module.exports ? module.exports : globalThis.nacl; |
I traced this to nkeys and submitted the PR referenced just above this comment. |
We use vitejs to do production builds (
vite build
). I think vitejs in turn uses rollup under the hood.When moving from
nats.ws
version1.8.1
to1.9.0
the production build stopped working.Specifically we get this error in the browser console:
Looking into the code that causes this it is minified but here is an excerpt:
It is the
nacl.sign
that fails. We tracked down why this is used and got to thenkeys
package which in turn is used bynats.ws
. Pinning the version ofnkeys
to1.0.0-9
when usingnats.ws
1.9.0
does not work (nats.ws
1.8.1
usesnkeys
1.0.0-9
and it does work).So for that reason I think the problem is not with
nkeys
itself but rather hownats.ws
does its call intonkeys
.The text was updated successfully, but these errors were encountered: