use "exports" field in package.json#1410
Conversation
|
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 CosmJs packages are only very lightly maintained by Confio these days, and they're all effectively CommonJs-only right now. cosmos/cosmjs#1649 (comment) Since it's not exported from the top level index.ts at all, the only ESM-compatible way to access that type is importing as |
253594c to
7ecd27f
Compare
cc3cf32 to
a1ebd02
Compare
9.1.0 is the version that added ESM support.
can't omit the file extension in ESM imports.
can't omit the file extension in ESM imports.
69ea0a6 to
13f93b4
Compare
node packages have standardized on this field since circa 2020.
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).