As proof of that, if you add this setting to your vitest config, globalSetup works
ssr: {
resolve: {
conditions: ['import']
}
}
However, then, tests using Postgres.js fail
FAIL test/index.spec.ts [ test/index.spec.ts ]
Error: No such module "Users/xxx/repro-vitest-pool-workers-import-error/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/os".
imported from "Users/xxx/repro-vitest-pool-workers-import-error/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/index.js"
I guess this is because resolve condition is no longer workerd. Vitest is trying to import files for runtime other than workerd.
Expected behavior
You can import postgres correctly
Steps to reproduce
Please provide the following:
run npm create cloudflare@latest and select Hello World example and then Hello World Worker
use Postgres.js in a global setup file and a test file
Which Cloudflare product(s) does this pertain to?
Workers Vitest Integration
What version(s) of the tool(s) are you using?
0.4.21
What version of Node are you using?
20.11.0
What operating system and version are you using?
Mac Sonoma 14.1.2
Describe the Bug
Observed behavior
Importing packages with
workerd
runtime key from globalSetup fails.I tried to use Postgres.js from a globalSetup file to run database migration, but this error was raised.
This is because
workerd
as one ofresolve.conditions
of vite configPostgres.js
hasworkerd
key in its export field, so the file forworkerd
runtime is loadedAs proof of that, if you add this setting to your vitest config, globalSetup works
However, then, tests using
Postgres.js
failI guess this is because resolve condition is no longer
workerd
. Vitest is trying to import files for runtime other thanworkerd
.Expected behavior
You can import postgres correctly
Steps to reproduce
Please provide the following:
npm create cloudflare@latest
and selectHello World example
and thenHello World Worker
npm run test
Please provide a link to a minimal reproduction
https://github.com/m-shaka/repro-vitest-pool-workers-import-issue
Please provide any relevant error logs
No response