pg 8.22.0 CJS entry can resolve pg-protocol as ESM under Cloudflare/Vite worker tests
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript, postgresql, vite
- 领域
- backend, build-system, databases
调研方向
从 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.0pg-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
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
brianc/node-postgres 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
brianc/node-postgres#3770 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
brianc/node-postgres#3716 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
brianc/node-postgres#3631 · 1 条评论 ·
-
难度 1/5 1-3 小时 新手友好度 62/100
brianc/node-postgres#2857 ·
-
难度 1/5 1 小时以内 新手友好度 68/100
brianc/node-postgres#2433 ·
查看 brianc/node-postgres 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
antfu-collective/icones#398 ·
-
ECmail.com 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
wesbos/burner-email-providers#554 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
radiantearth/stac-browser#1023 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
components-web-app/docs#92 ·