-
Notifications
You must be signed in to change notification settings - Fork 985
Open
Labels
bugSomething that isn't workingSomething that isn't workingvitestRelating to the Workers Vitest integrationRelating to the Workers Vitest integration
Description
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.
Error: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:'
This is because
- vitest-pool-workers set
workerd
as one ofresolve.conditions
of vite config - globalSetup is executed by Node.js, but
Postgres.js
hasworkerd
key in its export field, so the file forworkerd
runtime is loaded
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/[email protected]/node_modules/postgres/src/os".
imported from "Users/xxx/repro-vitest-pool-workers-import-error/node_modules/.pnpm/[email protected]/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 selectHello World example
and thenHello World Worker
- use Postgres.js in a global setup file and a test file
- run
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
Metadata
Metadata
Assignees
Labels
bugSomething that isn't workingSomething that isn't workingvitestRelating to the Workers Vitest integrationRelating to the Workers Vitest integration
Type
Projects
Status
Backlog