-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Environment
- @cloudflare/vitest-pool-workers: 0.8.40
- vitest: 3.2.4
- better-auth: 1.3.4
- jose: 5.10.0
- Node: 23.11.1
- OS: Windows 11
Please provide a link to a minimal reproduction
Description
When running integration tests with @cloudflare/vitest-pool-workers, dependencies that have different builds for Node.js vs browser/Worker environments (like jose used by better-auth) are resolved to their Node.js versions during SSR optimization/prebundling. This causes No such module "node:https" errors in the Worker runtime.
Reproduction
- Create a Cloudflare Worker that uses
better-auth(or any library usingjose) - Set up integration tests with
@cloudflare/vitest-pool-workers - Try to run tests that load the Worker with
SELF.fetch()
Config attempted:
defineWorkersProject({
resolve: {
conditions: ['worker', 'workerd', 'browser'],
mainFields: ['worker', 'browser', 'module', 'main'],
},
test: {
deps: {
optimizer: {
ssr: {
enabled: true,
include: ['better-auth', 'jose'],
},
},
},
},
})Error
Error: No such module "node:https".
imported from "node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/fetch_jwks.js"
Expected Behavior
The SSR optimizer should respect Worker/browser module resolution and use the browser builds of dependencies that provide them (via exports field in package.json).
Attempted solutions that didn't work:
- Setting
resolve.conditions: ['worker', 'workerd', 'browser'] - Setting
resolve.mainFields: ['worker', 'browser', 'module', 'main'] - Pre-bundling with SSR optimizer (
deps.optimizer.ssr.include) - Various alias configurations
Actual Behavior
The SSR optimizer always uses Node.js module resolution, causing Worker-incompatible code to be bundled.
Workaround
Build the Worker first and point tests at the built output:
- Build: pnpm build (or wrangler deploy --dry-run --outdir dist)
- Configure vitest to use built Worker:
poolOptions: {
workers: {
main: "./dist/typist/index.js", // Point to built Worker
// ... rest of config
}
}This bypasses Vite's module resolution entirely and uses the correctly bundled Worker.
Suggested Fix
- Make SSR optimizer respect resolve.conditions and resolve.mainFields
- Or provide an option to disable SSR optimization for specific packages
- Or document the main option more prominently as the solution for this issue
Please provide any relevant error logs
Using vars defined in .dev.vars
[vpw:warn] Workers AI and Vectorize bindings will access your Cloudflare account and incur usage charges even in testing. We recommend mocking any usage of these bindings in your tests.
[vpw:info] Starting single runtime for 1...
[mf:warn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2025-06-17",
but you've requested "2025-07-15". Falling back to "2025-06-17"...
[vitest-pool-workers] Failed to import "node:https" from "D:/DevDrive/Projects/typist/node_modules/.vite/vitest/2e22affa7c1eed532fe2ec786ca54cd4f8f87e0c/deps_ssr/better-auth.js". To resolve this, try bundling the relevant dependency with Vite. For more details, refer to https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/#module-resolution
workerd/server/fallback-service.c++:151: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FD%3A%2FDevDrive%2FProjects%2Ftypist%2Fnode_modules%2F.vite%2Fvitest%2F2e22affa7c1eed532fe2ec786ca54cd4f8f87e0c%2Fdeps_ssr%2Fbetter-auth.js&rawSpecifier=node%3Ahttps
[vitest-pool-workers] Failed to import "node:https" from "D:/DevDrive/Projects/typist/node_modules/.vite/vitest/2e22affa7c1eed532fe2ec786ca54cd4f8f87e0c/deps_ssr/better-auth.js". To resolve this, try bundling the relevant dependency with Vite. For more details, refer to https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/#module-resolution
workerd/server/fallback-service.c++:151: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FD%3A%2FDevDrive%2FProjects%2Ftypist%2Fnode_modules%2F.vite%2Fvitest%2F2e22affa7c1eed532fe2ec786ca54cd4f8f87e0c%2Fdeps_ssr%2Fbetter-auth.js&rawSpecifier=node%3Ahttps
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL worker-integration tests/worker/integration/some-test.integration.test.ts [ tests/worker/integration/some-test.integration.test.ts ]
Error: No such module "node:https".
imported from "D:/DevDrive/Projects/typist/node_modules/.vite/vitest/2e22affa7c1eed532fe2ec786ca54cd4f8f87e0c/deps_ssr/better-auth.js"
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯Metadata
Metadata
Assignees
Labels
Type
Projects
Status