-
Notifications
You must be signed in to change notification settings - Fork 109
use "exports" field in package.json #1410
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fantastic
Jest is tricky to get working with ESM code. jestjs/jest#13739 Specifically when tests are written in TypeScript. https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/ ...and their recommended configuration requires a newer version of ...and because Jest writes its own require() logic as part of its mocking feature, it's more restrictive than Node.js v20.19 which allows CJS code (the Jest test) to require() ESM code (the xchainjs module). Jest won't allow that, so the test has to be ESM too. ...except the tests aren't ESM. There are a whole ton of require() calls that are used to read and parse a nearby JSON file. They can't work in ESM:
|
ee58bf7
to
8bbb66c
Compare
f8edd47
to
f97511f
Compare
In order to make Jest work, since currently the tests only work when transpiled to CJS, and Jest refuses to let CJS code require ESM code, had to resort to conditional exports:
|
Never mind. The built ESM code in It only maybe works if a transpiler messes with it. Raw, it fails trying to import from cosmos/cosmjs-types#93
It looks like there's no actual ESM-compatible way to access that type, because it's not even exported from the top level index.ts. CosmJs packages are only very lightly maintained by Confio these days, and they're all effectively CommonJs-only right now. cosmos/cosmjs#1649 (comment) |
5d20c52
to
38fb86c
Compare
Its CommonJS code is so convoluted that node can't statically determine the named exports.
In 9.2.0+ you can't use the named export anymore like that, at least when you only use the type.
satisfies typescript's "verbatimModuleSyntax": true
node packages have standardized on this field since circa 2020.
@emurgo/cardano-serialization-lib-browser is an ESM-only package, and Jest gets stricter if you put type: module in your package.json.
https://nodejs.org/api/packages.html#exports
Without this field, Node.js import logic believes it's just a CJS package - node doesn't recognize the old non-standard
"module"
field (while transpilers like webpack do).