getting a few weird errors when trying

getting a few weird errors when trying to run this
workerd/server/server.c++:2676: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-validator%400.1.11_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-validator%2Fdist%2Fesm%2Findex.js&referrer=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-openapi%400.9.8_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-openapi%2Fdist%2Findex.mjs
workerd/server/server.c++:2676: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-validator%400.1.11_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-validator%2Fdist%2Fesm%2Findex.js&referrer=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-openapi%400.9.8_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-openapi%2Fdist%2Findex.mjs
the mentioned package @hono/zod-validator is installed and runs correctly when I run the worker via wrangler has anyone run into something similar?
22 Replies
chronark
chronarkOP•2y ago
here's a cleaner version of the error:
Error: No such module "Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/@hono/zod-validator".
imported from "Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/index.mjs"
Error: No such module "Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/@hono/zod-validator".
imported from "Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/index.mjs"
MrBBot
MrBBot•2y ago
Hey! šŸ‘‹ Could you post your full terminal output from running the command? If you could run with the NODE_DEBUG=vitest-pool-workers:module-fallback environment variable set, that would be great too. Although note this will generate a lot of output, so you might want to pipe it to a file.
chronark
chronarkOP•2y ago
sure thing, one sec
MrBBot
MrBBot•2y ago
Hmmm, that's interesting. It looks like @hono/zod-validator is being treated as a CommonJS module even though it's an ES module šŸ˜• I'm guessing this is because it's trying to load a .js file, but "type": "module" isn't included the package.json
chronark
chronarkOP•2y ago
let me rip it out and try again it's not super critical to use right now was I just blind and couldn't see that error or how did you know that's the issue?
MrBBot
MrBBot•2y ago
Yeah, looks like https://github.com/honojs/middleware/blob/main/packages/zod-validator/package.json doesn't include "type": "module", but this is because the package exports both CommonJS and ES modules. I think the fix is for Hono to update their ES module version to use the .mjs extension.
chronark
chronarkOP•2y ago
cool, I'll let them know
MrBBot
MrBBot•2y ago
Seen something similar before, this was the important part:
VITEST-POOL-WORKERS:MODULE-FALLBACK 18102: import("/Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-validator@0.1.11_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-validator/dist/esm/index.js") relative to /Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/index.mjs: error: Error: Parse error @7:1:8
at Module.parse (file:///Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/cjs-module-lexer@1.2.3/node_modules/cjs-module-lexer/dist/lexer.mjs:2:383)
at getCjsNamedExports (file:///Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@cloudflare+vitest-pool-workers@0.1.2_@cloudflare+workers-types@4.20240222.0_@vitest+runner@1_7mbdxuy4qanlvzhdssu3kelb2i/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:654:49)
VITEST-POOL-WORKERS:MODULE-FALLBACK 18102: import("/Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-validator@0.1.11_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-validator/dist/esm/index.js") relative to /Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/index.mjs: error: Error: Parse error @7:1:8
at Module.parse (file:///Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/cjs-module-lexer@1.2.3/node_modules/cjs-module-lexer/dist/lexer.mjs:2:383)
at getCjsNamedExports (file:///Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@cloudflare+vitest-pool-workers@0.1.2_@cloudflare+workers-types@4.20240222.0_@vitest+runner@1_7mbdxuy4qanlvzhdssu3kelb2i/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:654:49)
Essentially, a JavaScript file was failing to be parsed as CommonJS, which usually means it contains import/export statements.
chronark
chronarkOP•2y ago
aah ok ok I removed the package now it crashes with the next hono package šŸ˜„ I guess that's as far as I'll get today, thank you so much
MrBBot
MrBBot•2y ago
Oh dear ok. šŸ˜… Thanks for letting them know though. šŸ‘
chronark
chronarkOP•2y ago
do you know by chance if there's a way to override it locally? I'd love to try out the vitest integration properly without waiting on them I tried just adding type: module but the error remains
MrBBot
MrBBot•2y ago
Hmmm, I think renaming the dist/esm/*.js files to dist/esm/*.mjs and updating the package.json to use the new *.mjs files would work. Depending on how many packages you need to update, that might be a bit tedious though.
chronark
chronarkOP•2y ago
just one or two let me try, thank you hmm, there's actually no dist/esm at all, so maybe it's a different issue šŸ˜„
MrBBot
MrBBot•2y ago
Inside @hono/zod-validator? Or another package?
chronark
chronarkOP•2y ago
it's looking in /node_modules/.pnpm/...
No such module "Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/@hono/zod-validator".
No such module "Users/andreasthomas/github/unkeyed/unkey/node_modules/.pnpm/@hono+zod-openapi@0.9.8_hono@4.1.0_zod@3.22.4/node_modules/@hono/zod-openapi/dist/@hono/zod-validator".
but this is what actualyl exists:
No description
chronark
chronarkOP•2y ago
@hono/zod-validator is missing from that directory entirely or maybe I am misunderstanding how it should work
MrBBot
MrBBot•2y ago
Ah those paths aren't quite correct. When workerd sends a request to the module fallback service, it resolves the specifier with the referrer directory. So import("@hono/zod-validator") inside /a/b/c/index.mjs would result in a request for /a/b/c/@hono/zod-validator. Because workerd also sends the referrer, we're able to perform the reverse operation to get the actual specifier.
chronark
chronarkOP•2y ago
🤯 you wizards, you šŸ˜„
/?specifier=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-validator%400.1.11_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-validator%2Fdist%2Fesm%2Findex.js&referrer=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-openapi%400.9.8_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-openapi%2Fdist%2Findex.mjs
/?specifier=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-validator%400.1.11_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-validator%2Fdist%2Fesm%2Findex.js&referrer=%2FUsers%2Fandreasthomas%2Fgithub%2Funkeyed%2Funkey%2Fnode_modules%2F.pnpm%2F%40hono%2Bzod-openapi%400.9.8_hono%404.1.0_zod%403.22.4%2Fnode_modules%2F%40hono%2Fzod-openapi%2Fdist%2Findex.mjs
then I'll continue my search here šŸ™‚ aand there's the esm šŸ™‚
YoannMa
YoannMa•2y ago
Hi, having literally the same issue šŸ˜… @chronark Did you find a way to fix it without modifying every hono's middleware ?
chronark
chronarkOP•2y ago
nope, I gave up for now :/ I raised it in hono's discord but that's pretty messy and I think it just got lost
YoannMa
YoannMa•2y ago
Guess I'll give up, zod-openapi is broken as well Test are overrated anyway šŸ˜‚

Did you find this page helpful?