Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#3,700 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
javascript, postgresql, vite

調査の方向性

pg/lib/connection.js から始め、CommonJS エントリが pg-protocol、pg-pool、pg-connection-string のエントリポイントをどのように解決するかを調べます。@cloudflare/vitest-pool-workers と Vite の worker-test パイプラインで障害を再現し、その後、CommonJS エントリが pnpm のレイアウトに依存せずに互換性のある依存ファイルを読み込むことを確認します。

索引モデルが issue の本文から書いたものです。

説明

Summary

When pg@8.22.0 is bundled by the @cloudflare/vitest-pool-workers / Vite worker-test pipeline in a pnpm workspace, the CommonJS entry can fail while loading pg-protocol from pg/lib/connection.js:

SyntaxError: Cannot use import statement outside a module
  at node_modules/.pnpm/pg@8.22.0/node_modules/pg/lib/connection.js?mf_vitest_no_cjs_esm_shim:5:30
  at node_modules/.pnpm/pg@8.22.0/node_modules/pg/lib/client.js?mf_vitest_no_cjs_esm_shim:10:20
  at node_modules/.pnpm/pg@8.22.0/node_modules/pg/lib/index.js

The failing line is the CommonJS package-name require:

const { parse, serialize } = require("pg-protocol")

In this environment, that dependency can be resolved/transformed as an ES module, then loaded from a CJS wrapper.

Environment
  • pg: 8.22.0
  • pg-protocol: 1.15.0
  • package manager: pnpm
  • test/bundler stack: @cloudflare/vitest-pool-workers + Vite + Miniflare/workerd
  • worker compatibility flag: nodejs_compat
Local workaround

We currently patch pg to force the CJS files to load the CJS dependency files directly from pnpm's sibling layout:

-const { parse, serialize } = require("pg-protocol")
+const { parse, serialize } = require("../../pg-protocol/dist/index.js")

-const Pool = require("pg-pool")
+const Pool = require("../../pg-pool/index.js")

-const parse = require("pg-connection-string").parse
+const parse = require("../../pg-connection-string/index.js").parse

That patch is not a good general solution because it depends on pnpm's installed package layout.

Ask

Would pg consider an upstream change that makes the CommonJS entry robust in bundler/worker environments, for example by ensuring the CJS entry always resolves CJS-compatible dependency entrypoints for pg-protocol, pg-pool, and pg-connection-string?

Happy to provide more details or test a candidate fix.

主要言語
JavaScript
スター
13.2k
フォーク
1.4k
平均マージ
6日 15時間
マージ済み PR(30日)
6

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

brianc/node-postgres のほかの issue

brianc/node-postgres の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。