Repository navigation
fix(package): every entry point loads with require() - #29
Conversation
The export map offered only an `import` condition, so CommonJS callers, including CommonJS builds of TypeScript projects, failed with ERR_PACKAGE_PATH_NOT_EXPORTED. The modules have no top-level await and load fine through Node's require(esm) (20.19+, 22.12+), which is how those callers already load Effect 4. Each entry now also has a `default` condition pointing at the same .mjs, so CommonJS and ES module callers load one module and share one Effect. The package-consumer check now require()s every entry listed in the packed tarball's export map and compiles and decodes a query from CommonJS. With the old export map it fails with the original error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Maple review🟢 Confidence 8/10 · likely safe to merge Adds a
What was checked
|
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 6
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Each entry in
exportsnow has adefaultcondition besideimport, pointing at the same.mjs. CommonJS code canrequire()every entry point.Why
The export map offered only
import. Node'srequire()matchesrequire,nodeanddefault, neverimport, so every CommonJS caller failed withERR_PACKAGE_PATH_NOT_EXPORTED. That includes CommonJS builds of TypeScript projects, which compileimporttorequire.The modules themselves were never the problem. They have no top-level await, so Node 20.19+ and 22.12+ load them synchronously through
require(esm). That is already how such callers load Effect 4, which is also ESM-only. Becausedefaultpoints at the same file, a CommonJS caller and an ES module caller load one module instance and share one Effect.Found in superwall/paywall-next#4365, which had to carry a pnpm patch for this.
@superwall/apiships a CommonJS build and imports a query module that uses the builder. The patch can be dropped once this is released.Changes
package.json:defaultadded to all 12 entries.tests/package-consumer.cjsandscripts/check-package.ts:test:packagenow runs a CommonJS consumer against the packed tarball.require()s every entry, reading the list from the installed export map so that entries added later are covered.effectworks with the library.Testing
bun run test:packagepasses (CommonJS consumer ok (12 entries)).ERR_PACKAGE_PATH_NOT_EXPORTED, so the new check catches a regression.bun run typecheckpasses.bun run testpasses: 684 tests, plus the doc citation, export catalog and doc example checks. The 204 skipped tests are the live-ClickHouse tests, which need an endpoint.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit
require()on Node.js 20.19+ or 22.12+.uint64value.