Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

fix(npm): Route bare "zlib" imports through the ESM namespace shim - #1357

Merged
BYK merged 1 commit into
mainfrom
jp/allow-esm-export
Aug 4, 2026
Merged

BYK merged 1 commit into
mainfrom
jp/allow-esm-export

Conversation

@JPeer264

@JPeer264 JPeer264 commented Aug 4, 2026

Copy link
Copy Markdown
Member

The zlib-namespace-shim plugin only matched the "node:zlib" specifier, but bundled dependencies (binpatch) import from bare "zlib". esbuild hoisted those into top-level named imports of the version-gated zstd* family (added in Node 22.15), which fail at link time on older Node — the entire ESM entry of the npm package failed to load on Node 18/20, despite engines.node claiming >= 18.

Widen the filter to match both specifiers, and add a regression test that statically scans the built ESM bundle for link-fatal named zlib imports. (The existing dynamic import test only runs on the build Node, which already has zstd and can never catch this.)

Verified: dist/index.mjs now imports cleanly on Node 18.20.8 and 20.19.5; CJS unaffected.

The zlib-namespace-shim plugin only matched the "node:zlib" specifier,
but bundled dependencies (binpatch) import from bare "zlib". esbuild
hoisted those into top-level named imports of the version-gated zstd*
family (added in Node 22.15), which fail at link time on older Node —
the entire ESM entry of the npm package failed to load on Node 18/20,
despite engines.node claiming >= 18.

Widen the filter to match both specifiers, and add a regression test
that statically scans the built ESM bundle for link-fatal named zlib
imports. (The existing dynamic import test only runs on the build
Node, which already has zstd and can never catch this.)

Verified: dist/index.mjs now imports cleanly on Node 18.20.8 and
20.19.5; CJS unaffected.

Co-Authored-By: Claude <noreply@anthropic.com>
@JPeer264
JPeer264 requested review from BYK and betegon August 4, 2026 11:34
@JPeer264 JPeer264 self-assigned this Aug 4, 2026
@BYK BYK added the jared Trigger the Jared agent to work on stuff label Aug 4, 2026

@jared-outpost jared-outpost Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified the fix end-to-end. rebuilt dist/index.mjs with the old narrow /^node:zlib$/ filter and it does emit the link-fatal import{zstdDecompressSync,createZstdDecompress}from"zlib" — bundled binpatch imports from bare zlib, so esbuild hoisted the version-gated zstd names past the shim. widening to /^(?:node:)?zlib$/ routes those through the namespace shim: rebuilt bundle now has exactly one import * as ... from "node:zlib" and no named zstd import, and loads cleanly.

the regression test is real coverage, not decoration — it fails against the pre-fix bundle and passes against the fixed one. CJS path unaffected (shim is ESM-only). biome clean.

one nit, non-blocking: engines.node is >=20.0 but the PR body/comments mention Node 18 — the zstd gate is 22.15 either way so it doesn't affect the fix, just the prose.

@BYK
BYK merged commit a217181 into main Aug 4, 2026
31 checks passed
@BYK
BYK deleted the jp/allow-esm-export branch August 4, 2026 15:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

jared Trigger the Jared agent to work on stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants