Publish ESM and CommonJS runtime artifacts - #58
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4be16ca1e6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
| 'use strict'; | ||
|
|
||
| let Dataloader = require("dataloader").default; |
There was a problem hiding this comment.
Use DataLoader's CommonJS export directly
CommonJS consumers that use the published DataLoader.js runtime still fail once makeSingle/makeBatched constructs the loader: dataloader@2.x exposes the constructor as module.exports, so require("dataloader").default is undefined and new Dataloader(...) throws TypeError: Dataloader is not a constructor. The ESM build worked because ESM maps a CJS module.exports value to the default import, but this CJS artifact needs to require the value itself or otherwise unwrap both shapes.
Useful? React with 👍 / 👎.
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
| 'use strict'; | ||
|
|
||
| let GraphqlRelayConnectionsMjs = require("./graphqlRelayConnections.mjs"); |
There was a problem hiding this comment.
Don't require ESM helpers from CJS runtime files
On supported Node versions before require(esm) is enabled by default, such as Node 20.11–20.18 under the package's >=20.11.0 engine, loading this CommonJS runtime module throws at startup because it synchronously require()s a .mjs helper. The same pattern appears in ResGraph__Utils.js and DataLoader.js, so CommonJS consumers using connections, base64 utilities, or data loaders are still broken unless the helpers also have CJS outputs or the supported Node range is raised.
Useful? React with 👍 / 👎.
What
.mjs) and CommonJS (.js)Why
ReScript CommonJS consumers generate imports such as
resgraph/src/res/ResGraph.js. ResGraph 1.3.2 only published.mjs, so production-only installs crash at startup when generated authorization code loads the missing.jsruntime.Impact
This is additive for existing ESM users. CommonJS consumers can now load generated ResGraph runtime imports. The minimum supported ReScript version becomes 12.3.0.
Tests
npm run buildnpm run test:packageopam exec -- make testgit diff --check