pg 8.22.0 CJS entry can resolve pg-protocol as ESM under Cloudflare/Vite worker tests
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, postgresql, vite
- Ambito
- backend, build-system, databases
Direzione di ricerca
Inizia da pg/lib/connection.js e analizza il modo in cui l'entry CommonJS risolve gli entrypoint di pg-protocol, pg-pool e pg-connection-string. Riproduci il malfunzionamento con la pipeline di test dei worker di @cloudflare/vitest-pool-workers e Vite, quindi verifica che l'entry CommonJS carichi file di dipendenze compatibili senza dipendere dal layout di pnpm.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- JavaScript
- Stelle
- 13.2k
- Fork
- 1.4k
- Merge medio
- 6g 15h
- PR unite (30g)
- 6
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di brianc/node-postgres
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
brianc/node-postgres#3770 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
brianc/node-postgres#3716 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
brianc/node-postgres#3631 · 1 commento ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 62/100
brianc/node-postgres#2857 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
brianc/node-postgres#2433 ·
Tutte le issue di brianc/node-postgres
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
area-deployment area-integrations triage:bot-seen
Difficoltà 2/5 Mezza giornata Idoneità per principianti 86/100
-
Issue-Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
sugarlabs/musicblocks#8924 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
ArduPilot/ardupilot_wiki#8088 ·
-
[BUG] createTool tools cannot be registered with Mastra when exactOptionalPropertyTypes is enabled Apertacustomer-eng status: needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100