Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#3,700 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
6

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

brianc/node-postgres 的其他 Issue

查看 brianc/node-postgres 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。