Skip to content

fix(grabkit): add exports map with .mjs ESM build; treat empty 2xx as success - #1

Merged
mrlemoos merged 1 commit into
mainfrom
fix/esm-exports-and-empty-2xx
Oct 28, 2026
Merged

mrlemoos merged 1 commit into
mainfrom
fix/esm-exports-and-empty-2xx

Conversation

@mrlemoos

Copy link
Copy Markdown
Owner

Why

An end-to-end test of an analytics SDK built on grabkit turned up two bugs.

  1. Plain Node ESM gets a non-callable default import. package.json has main (CJS) and module (ESM) but no exports. Node ignores module, so import grabkit from 'grabkit' loads the CJS build, and the default import is the module object rather than the function. Bundlers (Vite, webpack, Next) read module, which is why this hasn't shown up before.
  2. An empty 2xx body is reported as a transport error. Only 204, 205 and 304 counted as empty successes. A fire-and-forget endpoint that answers 202 Accepted with no body came back as GrabkitTransportError: empty response body, even though the request worked.

What changed

  • The ESM build is now emitted as build/esm/grabkit.mjs.
  • exports routes import to the ESM build and require to the CJS build. types and ./package.json are exported too.
  • An empty body on any 2xx now returns [null, null, { statusCode }], the same as 204. An empty non-2xx response still fails.

Tests

  • grabkit.test.ts: empty 200, 201 and 202 count as success; an empty 500 still fails. These were written first and failed before the fix.
  • publishBundle.test.ts: imports the package by name under Node ESM and CJS and asserts the default export is a function. This fails on main under ESM.
  • grabkit:test passes (26 tests), and so does grabkit-integration:test.
  • I also packed the tarball and installed it into a clean type: module project. The default import is callable under both ESM and CJS, and an empty 202 from a local server returns error: null, status: 202.

Release notes

  • This may need a major version. An exports map blocks deep imports such as grabkit/build/esm/grabkit.js, and the ESM file is renamed.
  • The committed version is out of date. packages/grabkit/package.json says 2.0.1, but npm has 2.1.0, so it looks like the release step doesn't commit the version bump.

🤖 Generated with Claude Code

… success

Without an exports map, Node ESM consumers resolved the CJS build and got
a non-callable default import. Ship the ESM build as .mjs and route
import/require through exports.

An empty body on 200/201/202 was a GrabkitTransportError, so fire-and-
forget endpoints (e.g. 202 Accepted) always looked failed. Treat any empty
2xx like 204: success with null data. Empty non-2xx still fails.

Note: exports blocks deep imports such as grabkit/build/esm/grabkit.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
grabkit.dev Ready Ready Preview Oct 28, 2026 2:01am UTC

@mrlemoos
mrlemoos merged commit d54aa25 into main Oct 28, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — c3a22bf5 Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant