-
Notifications
You must be signed in to change notification settings - Fork 111
Import of postgres ("pg") breaks when using nuxt test-utils in combination with vitest >= 4.1.0 #1635
Description
Environment
| Operating system | Linux 6.6.87.2-microsoft-standard-WSL2 |
| CPU | AMD Ryzen 7 7700X 8-Core Processor (16 cores) |
| Node.js version | v24.14.1 |
| nuxt/cli version | 3.34.0 |
| Package manager | npm@11.11.0 |
| Nuxt version | 4.4.2 |
| Nitro version | 2.13.2 |
| Builder | vite@7.3.1 |
| Config | compatibilityDate, devtools |
| Modules | - |
Reproduction
https://github.com/konstantin-lukas/vitest-4.1.0-repro
Describe the bug
I orginally posted this issue here in the vitest repo as this issue first started appearing after upgrading from vitest v4.0.18 to v4.1.0.
TypeError: Class extends value [object Module] is not a constructor or null
❯ poolFactory node_modules/pg/lib/index.js:14:3
❯ new PG node_modules/pg/lib/index.js:25:15
❯ Object.<anonymous> node_modules/pg/lib/index.js:50:18
If you investigate the source files, you will see that the Pool exported from "pg" is a factory function that returns a class that extends the Pool class from "pg-pool". This leads me to believe that the underlying issue has something to do with module resolution. It could be something like cjs getting wrapped to fit esm or something. However, I tried importing different entrypoints from "pg" but to no avail.
You will see that if you remove nuxt test utils from the example, that the test runs without problem. The issue on vitest was closed and I was told to post it here.
Thank you for your time and effort :)
Additional context
No response