-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 BUG: Discrepancy in Node Module Compatibility Between wrangler deploy and vitest-pool-workers Testing #7324
Comments
|
Thanks! My workaround is to create a sister testing repo of my production Workers repo without those polyfilled deps. If there's a better workaround, please advise. Otherwise I'm glad to know it's not due to improper configuration. Feel free to close and track as desired. |
|
Ah whoops sorry I was totally mistaken - there is a way to get around this @zach-is-my-name if you use wrangler to build + add polyfills, you can then point vitest at the output which will be the same as what wrangler deploys. |
Thanks @emily-shen. [~/tmp/reproduction-vitest-pool-compat-module-error]$ ls dist
README.md index.js index.js.map
[~/tmp/reproduction-vitest-pool-compat-module-error]$ head wrangler.toml
#:schema node_modules/wrangler/config-schema.json
name = "hello-world"
main = "src/index.ts"
compatibility_date = "2024-11-12"
compatibility_flags = ["nodejs_compat_v2"]
[~/tmp/reproduction-vitest-pool-compat-module-error]$ cat test/vitest.config.ts
import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config";
import path from 'path';
export default defineWorkersProject({
test: {
poolOptions: {
workers: {
main: "../dist/index.js",
wrangler: { configPath: path.resolve(__dirname, '../wrangler.toml') },
},
},
},
}); [~/tmp/reproduction-vitest-pool-compat-module-error]$ bun run test
$ vitest run --config test/vitest.config.ts
RUN v2.0.5 /Users/zm/tmp/reproduction-vitest-pool-compat-module-error
[vpw:inf] Starting isolated runtimes for test/vitest.config.ts...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2024-11-06",
but you've requested "2024-11-12". Falling back to "2024-11-06"...
workerd/server/server.c++:3112: error: Fallback service failed to fetch module; exception = workerd/server/workerd-api.c++:416: failed: expected featureFlags.getNodeJsCompat(); The nodejs_compat compatibility flag is required to use the nodeJsCompatModule type.
stack: 102a1050f 1029dd94f; spec = /?specifier=%2FUsers%2Fzm%2Ftmp%2Freproduction-vitest-pool-compat-module-error%2Fnode_modules%2F%40cloudflare%2Fvitest-pool-workers%2Fdist%2Fworker%2Flib%2Fcloudflare%2Fmock-agent.cjs%3Fmf_vitest_no_cjs_esm_shim&referrer=%2FUsers%2Fzm%2Ftmp%2Freproduction-vitest-pool-compat-module-error%2Fnode_modules%2F%40cloudflare%2Fvitest-pool-workers%2Fdist%2Fworker%2Flib%2Fcloudflare%2Fmock-agent.cjs&rawSpecifier=.%2Fmock-agent.cjs%3Fmf_vitest_no_cjs_esm_shim
service core:user:vitest-pool-workers-runner-: Uncaught Error: No such module "Users/zm/tmp/reproduction-vitest-pool-compat-module-error/node_modules/@cloudflare/vitest-pool-workers/dist/worker/lib/cloudflare/mock-agent.cjs?mf_vitest_no_cjs_esm_shim".
imported from "Users/zm/tmp/reproduction-vitest-pool-compat-module-error/node_modules/@cloudflare/vitest-pool-workers/dist/worker/lib/cloudflare/mock-agent.cjs" |
Argh sorry my bad 🤦 . In your integration test you're still importing from |
Thanks @emily-shen! I'll check it out. Please allow a few more days I'm working on resolving other |
I'm going to close this as I don't have the bandwidth to follow-up. |
I just hit this issue as well today. @emily-shen is the current recommendation still to do a full build before running tests? That would significantly slow down our testing feedback loop while running them locally. Are there any other options? Please advise, thank you! |
Which Cloudflare product(s) does this pertain to?
Workers Vitest Integration
What version(s) of the tool(s) are you using?
Wrangler 3.83, "vitest": "^2.1.5", "@cloudflare/vitest-pool-workers": "^0.5.28",
What version of Node are you using?
v20.13.1
What operating system and version are you using?
Mac Sonoma 15.3
Describe the Bug
Description:
I'm experiencing an issue where my Cloudflare Worker with Durable Objects works correctly when deployed using
wrangler deploy
, but fails during testing withvitest-pool-workers
due to Node module compatibility problems.Problem Summary:
Deployment Works as Expected:
wrangler deploy
, it successfully handles Node module dependencies through compatibility transformations.wrangler
correctly replaces or polyfills Node-specific modules to make them compatible with the Workers environment.Testing Fails Due to Node Dependencies:
vitest
and@cloudflare/vitest-pool-workers
, the same Worker code fails to execute.wrangler deploy
.Details:
Node Dependencies in Use:
https
from'node:https'
and usesWallet
andkeccak256
from theethers
library.Testing Setup:
vitest
along with@cloudflare/vitest-pool-workers
to test my Worker.vitest.config.ts
is configured usingdefineWorkersProject
from@cloudflare/vitest-pool-workers/config
.Error Messages During Testing:
When running tests, I encounter errors like:
This indicates that the Node modules are not being resolved or replaced in the testing environment.
Expected Behavior:
vitest-pool-workers
should handle Node module compatibility in the same way aswrangler deploy
.Questions and Request for Assistance:
Is there a way to configure
vitest-pool-workers
to perform the same Node module compatibility transformations aswrangler deploy
?Are there recommended practices for testing Workers that depend on Node modules using
vitest-pool-workers
?Could this be a limitation or missing feature in
vitest-pool-workers
that needs to be addressed?Steps to Reproduce:
Create a Worker with Node Dependencies:
node:https
and usesethers
.Deploy the Worker:
wrangler deploy
to deploy the Worker.Set Up Testing Environment:
Install
vitest
and@cloudflare/vitest-pool-workers
.Configure
vitest.config.ts
usingdefineWorkersProject
:Run Tests:
vitest
to run the tests.Additional Information:
Environment Details:
vitest
version: [Please specify]@cloudflare/vitest-pool-workers
version: [Please specify]wrangler
version: [Please specify]Attempts to Resolve:
vitest
configuration, including usingdefineConfig
and specifyingpool: '@cloudflare/vitest-pool-workers'
, but the issue persists.wrangler
during deployment is not available or not activated during testing.Conclusion:
I believe there may be a discrepancy between how
wrangler deploy
andvitest-pool-workers
handle Node module compatibility. I would appreciate any guidance on resolving this issue or insights into whether this is a known limitation.Thank you for your assistance!
Please provide a link to a minimal reproduction
https://github.com/zach-is-my-name/reproduction-vitest-pool-compat-module-error
Please provide any relevant error logs
Click to expand
[~/Projects/charli/apps/session-time-tracker]$ bun run test $ vitest run --config tests/vitest.config.tsRUN v2.1.5 /Users/zm/Projects/charli/apps/session-time-tracker
Using vars defined in .dev.vars
[vpw:inf] Starting isolated runtimes for tests/vitest.config.ts...
❯ tests/sessionTimer.test.ts (0)
❯ SessionTimer Durable Object (0)
❯ tests/websocketEndpoint.test.ts (3)
❯ POST /websocket (3)
× should process peer:joined websocket event
· should return error for invalid signature
· should return error for unsupported event type
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FUsers%2Fzm%2FProjects%2Fcharli%2Fapps%2Fsession-time-tracker%2Fnode_modules%2Fethers%2Flib.esm%2Futils%2Fgeturl.js&rawSpecifier=node%3Ahttps
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FUsers%2Fzm%2FProjects%2Fcharli%2Fapps%2Fsession-time-tracker%2Fnode_modules%2Fethers%2Flib.esm%2Futils%2Fgeturl.js&rawSpecifier=node%3Ahttps
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FUsers%2Fzm%2FProjects%2Fcharli%2Fapps%2Fsession-time-tracker%2Fnode_modules%2Fethers%2Flib.esm%2Futils%2Fgeturl.js&rawSpecifier=node%3Ahttps
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FUsers%2Fzm%2FProjects%2Fcharli%2Fapps%2Fsession-time-tracker%2Fnode_modules%2Fethers%2Flib.esm%2Futils%2Fgeturl.js&rawSpecifier=node%3Ahttps
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FUsers%2Fzm%2FProjects%2Fcharli%2Fapps%2Fsession-time-tracker%2Fnode_modules%2Fethers%2Flib.esm%2Futils%2Fgeturl.js&rawSpecifier=node%3Ahttps
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=node%3Ahttps&referrer=%2FUsers%2Fzm%2FProjects%2Fcharli%2Fapps%2Fsession-time-tracker%2Fnode_modules%2Fethers%2Flib.esm%2
❯ tests/connectionManager.test.ts (0)
❯ tests/initEndpoint.test.ts (0)
❯ tests/sessionTimer.test.ts (0)
❯ SessionTimer Durable Object (0)
❯ tests/webSocketManager.test.ts (0)
❯ tests/webhookEndpoint.test.ts (0)
❯ tests/websocketEndpoint.test.ts (3)
❯ POST /websocket (3)
× should process peer:joined websocket event
× should return error for invalid signature
× should return error for unsupported event type
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 6 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL tests/connectionManager.test.ts [ tests/connectionManager.test.ts ]
FAIL tests/initEndpoint.test.ts [ tests/initEndpoint.test.ts ]
FAIL tests/webSocketManager.test.ts [ tests/webSocketManager.test.ts ]
FAIL tests/webhookEndpoint.test.ts [ tests/webhookEndpoint.test.ts ]
Error: No such module "node:https".
imported from "Users/zm/Projects/charli/apps/session-time-tracker/node_modules/ethers/lib.esm/utils/geturl.js"
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/9]⎯
FAIL tests/sessionTimer.test.ts [ tests/sessionTimer.test.ts ]
Error: No test found in suite tests/sessionTimer.test.ts
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/9]⎯
FAIL tests/sessionTimer.test.ts > SessionTimer Durable Object
Error: No test found in suite SessionTimer Durable Object
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/9]⎯
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL tests/websocketEndpoint.test.ts > POST /websocket > should process peer:joined websocket event
AssertionError: expected 404 to be 200 // Object.is equality
❯ tests/websocketEndpoint.test.ts:51:29
49| });
50|
51| expect(response.status).toBe(200);
| ^
52| const text = await response.text();
53| expect(text).toBe('Webhook processed successfully');
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/9]⎯
FAIL tests/websocketEndpoint.test.ts > POST /websocket > should return error for invalid signature
AssertionError: expected 404 to be 401 // Object.is equality
❯ tests/websocketEndpoint.test.ts:78:29
76| });
77|
78| expect(response.status).toBe(401);
| ^
79| const data = await response.json() as { status: string; message: string };
80|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/9]⎯
FAIL tests/websocketEndpoint.test.ts > POST /websocket > should return error for unsupported event type
AssertionError: expected 404 to be 400 // Object.is equality
❯ tests/websocketEndpoint.test.ts:98:29
96| });
97|
98| expect(response.status).toBe(400);
| ^
99| const data = await response.json() as { status: string; message: string };
100|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/9]⎯
Test Files 6 failed (6)
Tests 3 failed (3)
Start at 18:38:11
Duration 918ms (transform 107ms, setup 131ms, collect 51ms, tests 52ms, environment 0ms, prepare 935ms)
[vpw:dbg] Shutting down runtimes...
The text was updated successfully, but these errors were encountered: