Open noook opened 6 months ago
As I can see, Nitro's build output is in *.mjs
, due to which, it uses import
rather than require
.
DB0 outputs both mjs and cjs files. cjs file's build is updated to handle the case in build process and has var _pg = require("pg"); const client = new _pg.Client(....
On the other hand, import statement uses destructured imports which is causing the issue.
This might be because, pg
was not written to work with esm.
After running above fix on the provided reproduction, I can verify that the issue gets resolved.
Seems esm imports not work at all in pg. https://github.com/brianc/node-postgres/issues/3060 https://github.com/brianc/node-postgres/pull/2534
ClientConfig also not imports in my project. Same env as TS, but on Nuxt.
Environment
Node.js: Reproducible with
v18.18.0
andv21.6.2
db0@0.1.4 pg@8.11.3
Reproduction
https://stackblitz.com/edit/github-xvw4kq?file=package.json
Describe the bug
Given the following configuration:
The server fails to start because the
Client
import from "pg" does not seem to be exported.Additional context
I'm not sure what's happening here, but I can run this with no issue.
I tried integrating without nitro's
useDatabase
withpg
, and I am obliged to instantiate the client this way:Logs