How to connect Vite, Hono and Cloudflare Workers?
I am trying to connect Hono with Vite on Cloudflare Workers, everything works, but the wrangler config. for some reason even with the adapter, the
wrangler.toml
doesn't get picked up and it fails to load environment variables.
18 Replies
This might be helpful, idk: https://github.com/yusukebe/hono-vite-react-stack
GitHub
GitHub - yusukebe/hono-vite-react-stack: Vite plugin for Hono and R...
Vite plugin for Hono and React on Cloudflare Workers - yusukebe/hono-vite-react-stack
hmm they are using the
@cloudflare/vite-plugin
and not the Hono dev server
I assumed workers are compatible with the Hono dev serverThe repo is an example setup from the Hono creator, so I’d consider it ‘best practice’ for Hono
I haven’t run Vite + Cloudflare, so I’m not sure how all the pieces (e.g., dev server) fit together, but I’d try using the above link as a reference
Hmm theres an adapter for the dev server that should work with workers
but it doesn't pick the wrangler.toml up
Rip
I’m on mobile rn so I can’t take a closer look
I appriciate your help so far, thanks!
No problem!
Do you have wrangler + miniflare installed?
yeah
What do you have in your toml that isn’t getting read?
the environment variables
Hmmm
How are you accessing them?
they should be hoisted to the context
also I assume the binding for KV and R2 isn't working aswell
Do you have a repo you can share?
I can make one
Thanks. I can’t think of anything else off the dome
@DangerZone here’s a hono + cf + vite example with the dev server: https://github.com/oscarvz/cf-workers-hono-client-side
does it detect and use the wrangler toml?
it looks exactly like what I am doing
The dev server worked for me to run the app, it just didn’t pick up any one of the wrangler toml binding
It uses the
toml
to grab static assets, so it should. I haven’t run it though
If you have an example repo to share, I’m happy to take a look later today or tomorrowahh I created one, tested it and it works
i'll go back to my original repo to check what is going wrong on my side.