-
Notifications
You must be signed in to change notification settings - Fork 60
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
index.js exports overwrite exports in jest context #75
Comments
lemoustachiste
added a commit
to blockchain-certificates/cert-verifier-js
that referenced
this issue
Jul 17, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I've been dealing with a strange error for the past week and I finally managed to pinpoint the issue.
My project has subdependency to this project through other third parties.
When I am testing the build with jest, my main exported class is undefined.
I've dived into jest code and what jest does is a transpile of my esm module back to commonjs to work with its internals.
To do so, it wraps the ESM module into a function that takes a few parameters as entry, and one of them is called
exports
within that function, and is a reference tomodule.exports
as seen here: https://github.com/jestjs/jest/blob/main/packages/jest-runtime/src/index.ts#L1578So now, as sha.js' code is added into my module, this bit (https://github.com/browserify/sha.js/blob/master/index.js#L1) is overwriting that higher level
exports
object, making my class unavailable for jest tests.I have made a local patch with this interface rather:
And now my tests can retrieve my class and run as expected. It seems that the
exports
variable is only for simplicity and scope level check of support, so it wouldn't break consumption in my opinion.I'm not sure what to do from there, I'd rather not make a fork (especially that this is not a first level dependency, so I'd have to make a dirtier hack in my package to ensure which version is consumed) but it also seems that this package does not get much attention these days. I'm happy to open a PR, but I would also like to have your feedback first, to find the best option for all of us.
Thanks for your support
The text was updated successfully, but these errors were encountered: