Skip to content

fix: use pg-protocol CommonJS entrypoint - #3749

Draft
zfaustk wants to merge 1 commit into
brianc:masterfrom
zfaustk:fix/pg-protocol-cjs-import
Draft

fix: use pg-protocol CommonJS entrypoint#3749
zfaustk wants to merge 1 commit into
brianc:masterfrom
zfaustk:fix/pg-protocol-cjs-import

Conversation

@zfaustk

@zfaustk zfaustk commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #3700.

Problem

When the Cloudflare Vitest/Vite worker pipeline inlines both pg and pg-protocol, the CommonJS pg entry can resolve the bare pg-protocol import through its ESM condition. Loading that ESM wrapper from pg's CommonJS files then fails before any tests run:

SyntaxError: Cannot use import statement outside a module
at pg/lib/connection.js?mf_vitest_no_cjs_esm_shim:5:30

I reproduced this with the standalone fixture from #3700 using released pg@8.23.0, pg-protocol@1.16.0, @cloudflare/vitest-pool-workers@0.16.18, and Vitest 4.1.9.

Fix

  • load pg-protocol/dist/index.js explicitly from pg's two CommonJS entry files;
  • add a unit regression that verifies the subpath is exported and both call sites keep using it.

This remains package-manager independent: pg-protocol exposes ./dist/*.js through its public exports map, and pg currently depends on pg-protocol ^1.16.0.

Tests

  • published standalone worker fixture: fails before the patch, passes 1/1 after it;
  • make test-unit from packages/pg;
  • yarn lint;
  • yarn build;
  • Prettier check for all changed files;
  • git diff --check.

The full PostgreSQL/Node matrix was not run locally; it is left to CI. The repository's existing Cloudflare integration test also gets past module collection with the worker inline settings after the patch, then stops at this executor's unavailable PostgreSQL endpoint.

Implementation and test preparation were assisted by Codex. The reproduction and all reported checks above were run against this branch.

@charmander

Copy link
Copy Markdown
Collaborator

This seems like a build misconfiguration, not a pg issue that should be fixed by changing the imports in this way.

@zfaustk
zfaustk marked this pull request as draft August 13, 2026 04:48
@zfaustk

zfaustk commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — agreed. The reproduction showed the worker build selecting the ESM
condition for a CommonJS caller, but changing pg's imports fixes that at the
wrong layer. I'll take this out of review and investigate the Vite/Workers
configuration instead.

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.

pg 8.22.0 CJS entry can resolve pg-protocol as ESM under Cloudflare/Vite worker tests

2 participants