Skip to content

fix(pg-protocol): ship the ESM entry as esm/index.mjs - #3807

Open
WolfieLeader wants to merge 1 commit into
brianc:masterfrom
WolfieLeader:fix/pg-protocol-esm-mjs
Open

WolfieLeader wants to merge 1 commit into
brianc:masterfrom
WolfieLeader:fix/pg-protocol-esm-mjs

Conversation

@WolfieLeader

Copy link
Copy Markdown

pg-protocol is the only package from #3423 whose ESM wrapper is a .js file in a package without "type": "module". The other packages use esm/index.mjs. Node loads the wrapper as ESM only through module syntax detection. Without detection, a named import fails:

SyntaxError: Named export 'parse' not found. The requested module 'pg-protocol' is a CommonJS module

That happens by default on Node 18, and on any version with --no-experimental-detect-module.

Change: rename packages/pg-protocol/esm/index.js to esm/index.mjs (same content) and point exports["."].import at it. "files" already ships /esm.

Test: packages/pg-esm-test/pg-protocol.test.js imports pg-protocol in a child Node process with detection off.

Node before after
18.20.8 fail 4 pass
20.20.2 fail 4 pass
22.23.3 fail 4 pass
26.8.2 fail 4 pass

Full pg-esm-test suite on Node 26: 37 pass. pg-protocol mocha suite: 78 passing.

When the package's real path is outside node_modules (a workspace link, for example), Node 26 also prints a MODULE_TYPELESS_PACKAGE_JSON warning for the old file. The .mjs name removes it.

Related to #3700, but this does not fix it. That failure comes from @cloudflare/vitest-plugin resolving require() with the import condition (cloudflare/workers-sdk#12984).

Risk: a deep import of pg-protocol/esm/index.js breaks. exports never exposed ./esm/*, so that path was not importable through exports.

pg-protocol is the only package from brianc#3423 whose ESM wrapper is a .js
file in a package without "type": "module". Node loads it as ESM only
through module syntax detection. Without detection (Node 18, or
--no-experimental-detect-module), `import { parse } from 'pg-protocol'`
fails with "Named export 'parse' not found".

Rename it to esm/index.mjs, like pg, pg-pool, pg-cursor and the other
packages.
@WolfieLeader
WolfieLeader marked this pull request as ready for review October 6, 2026 14:54
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