Failed deploy with Hono, Vite and email event handler
I'm building a email disposable service with Cloudflare workers. When I deploy using
vite build --mode client && vite build && wrangler deploy --no-bundle
I get the error: A request to the Cloudflare API (/accounts/xxx/workers/scripts/disposible-email/versions) failed. Uncaught TypeError: Cannot read properties of undefined (reading 'map') at null.<anonymous> (index.js:1:21247) in route [code: 10021]
.
I already figured out that the problem lies with export default { fetch: app.fetch, email: async (message, env) => {}
because when I export app
like export default app
the error does not occur. When I use export default { fetch: app.fetch }
the error will occur.
My entrypoint (index.tsx
) looks like this:
I used https://fiberplane.com/blog/client-side-guide/ to setup the project.Fiberplane
Step-by-step guide: Adding client-side logic to your Hono app
A guide to adding client-side logic to your Hono app.
11 Replies
hey! discord supports markdown codeblock syntax highlighting. just add the language after the opening backticks!
it makes it much easier to scan snippets
as a side-note, it's probably worth applying the
jsxRenderer
middleware only to routes/endpoints that use it
just to confirm, when you use
you get the error?
i'd also recommend the official hono docs/readmes as a primary reference
https://github.com/honojs/vite-plugins
https://hono.dev/docs/guides/jsx-dom@ambergristle Thank you for your answer! I read the documentation but couldn't find the way to go from the
cloudflare-workers
starter using yarn create hono
to a way to use the client components. What I did found was https://github.com/honojs/examples/tree/main/hono-vite-jsx mentioned on the vite-plugins repo you send. Using the code with the cloudflare-workers
started I got the same error when using export default { fetch: app.fetch }
.
I uploaded the code to a repo: https://github.com/shaunjanssens/hono-tsx
Can you please check what I'm doing wrong? Thank you!GitHub
examples/hono-vite-jsx at main ยท honojs/examples
Examples using Hono. Contribute to honojs/examples development by creating an account on GitHub.
GitHub
GitHub - shaunjanssens/hono-tsx: Support example using Hono, client...
Support example using Hono, client components and Cloudflare workers - shaunjanssens/hono-tsx
sorry to hear you're still having issues, and thanks for setting up the repo!
i'm looking into it now
i did notice that there appears to be a redundancy in your script
vite build --mode client && vite build && wrangler deploy --no-bundle
or is that to build the client + server separately?I honnestly don't have any idea, I suppose I just tried multiple things. The repo I shared now has the dev and build command I copied from the example and I added the deploy command with Wrangler.
The thing I would like to achieve is to have a single command to deploy both the frontend and the email worker.
Important to mention is that
yarn dev
and yarn build
works like it should, but when running yarn deploy
I get the error:
yeah, i can repro the error
this is the failing code: https://github.com/honojs/hono/blob/a2ec84866b21fe830d88ebb5f69e32b3bdfe71fc/src/hono-base.ts#L212
the error tells you where to look in the built app:
(
index.js:1:20275
)
not sure yet why that's breaking
@Shaun to streamline troubleshooting a bit, you can also run wrangler dev ./dist/index.js
That's handy indeed! Is there anything else I can try? I can't be the only person that tried to use client components with Vite and
export default { fetch: app.fetch}
, right?i actually just came across this issue that seems relevent: https://github.com/honojs/vite-plugins/issues/214
also maybe
- https://github.com/honojs/vite-plugins/issues/21
- https://github.com/honojs/vite-plugins/issues/190
nothing really authoritative from the mainters though, so idk
@Aditya Mathur, do you have a take on this?
@Shaun you could also check out this repo: https://github.com/Alwurts/honc-slide-generator
it uses a somewhat different approach + plugin, but may be a workaround
That's a nice find!
i reached out to @Nlea and @boots. they're my go-tos for cloudflare+hono questions
@ambergristle I also created an issue on Github (https://github.com/honojs/hono/issues/3955). For now I will just use two projects. One for the email worker and one for the front-end. That prevents using workarounds and will be easier to combine them when a proper fix is created. Thank you very much for all the help!
GitHub
Issues ยท honojs/hono
Web framework built on Web Standards. Contribute to honojs/hono development by creating an account on GitHub.
No problem! Thanks for opening an issue