Describe the bug
After upgrading from v4.0.18 to v4.1.0 (specifically I found that this issue was introduced in v4.1.0-beta.5) my integration tests no longer work because the "pg" module throws an error:
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 notice that the reproduction runs with the nuxt/vue test utils. The vitest config uses defineVitestProject from @nuxt/test-utils, so the issue could also be there but since the issue first started appearing after updating vitest, it would also be reasonable to assume that this a regression but it could very well be some sort of incompatibility.
Thank you for your time and work. It's much appreciated :)
Reproduction
- Clone this repository: https://github.com/konstantin-lukas/vitest-4.1.0-repro
- run
npm i to install deps
- run
npm test to run vitest
- You should see the described error
System Info
System:
OS: Linux 6.6 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
CPU: (16) x64 AMD Ryzen 7 7700X 8-Core Processor
Memory: 10.20 GB / 15.20 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.14.1 - /home/konst/.nvm/versions/node/v24.14.1/bin/node
npm: 11.11.0 - /home/konst/.nvm/versions/node/v24.14.1/bin/npm
npmPackages:
vitest: ^4.1.2 => 4.1.2
Used Package Manager
npm
Validations
Describe the bug
After upgrading from v4.0.18 to v4.1.0 (specifically I found that this issue was introduced in v4.1.0-beta.5) my integration tests no longer work because the "pg" module throws an error:
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 notice that the reproduction runs with the nuxt/vue test utils. The vitest config uses defineVitestProject from @nuxt/test-utils, so the issue could also be there but since the issue first started appearing after updating vitest, it would also be reasonable to assume that this a regression but it could very well be some sort of incompatibility.
Thank you for your time and work. It's much appreciated :)
Reproduction
npm ito install depsnpm testto run vitestSystem Info
System: OS: Linux 6.6 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat) CPU: (16) x64 AMD Ryzen 7 7700X 8-Core Processor Memory: 10.20 GB / 15.20 GB Container: Yes Shell: 5.2.21 - /bin/bash Binaries: Node: 24.14.1 - /home/konst/.nvm/versions/node/v24.14.1/bin/node npm: 11.11.0 - /home/konst/.nvm/versions/node/v24.14.1/bin/npm npmPackages: vitest: ^4.1.2 => 4.1.2Used Package Manager
npm
Validations