pg 8.22.0 CJS entry can resolve pg-protocol as ESM under Cloudflare/Vite worker tests
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript, postgresql, vite
- Lĩnh vực
- backend, build-system, databases
Hướng nghiên cứu
Bắt đầu từ pg/lib/connection.js và kiểm tra cách entry CommonJS phân giải các entrypoint của pg-protocol, pg-pool và pg-connection-string. Tái hiện lỗi với pipeline kiểm thử worker của @cloudflare/vitest-pool-workers và Vite, sau đó xác minh rằng entry CommonJS tải các tệp dependency tương thích mà không phụ thuộc vào layout của pnpm.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- JavaScript
- Star
- 13.2k
- Fork
- 1.4k
- Merge trung bình
- 6 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 6
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của brianc/node-postgres
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
brianc/node-postgres#3770 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
brianc/node-postgres#3716 · 1 bình luận ·
-
# remove bring your own promise Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
brianc/node-postgres#3631 · 1 bình luận ·
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
brianc/node-postgres#2857 ·
-
can't view docs for old versions Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
brianc/node-postgres#2433 ·
Tất cả issue của brianc/node-postgres
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
mksglu/context-mode#1200 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
neondatabase/website#5944 ·
-
module: core
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
bigbluebutton/bigbluebutton#25849 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
jaegertracing/jaeger-ui#4506 ·