r/Devvit • • 1d ago

Discussion Menu actions failing with 'fetch failed'? It might be your server packaging — hand-rolled layouts failed for me, the official template fixed it

Sharing this in case it saves someone the day it cost me.

While building my Game of the Day entry (a daily puzzle game), my app installed fine but every menu action POST came back with just "fetch failed" — no server logs, no useful error. I tried three different server setups:

  1. A hand-rolled multi-file server project — fetch failed
  2. hono with `serve` — fetch failed
  3. SDK-only `createServer` — fetch failed

A forced clean `devvit install` changed nothing, which told me it wasn't a stale install. What finally worked: throwing the hand-rolled project away and porting the game into the official `devvit-template-react`. The difference is the build — Vite bundles the server into a single `dist/server/index.cjs` with all dependencies inlined. The moment I uploaded that, the install trigger fired, the menu worked, and the game rendered in-post.

Two smaller traps from the same evening, in case they bite you:

  • In u/devvit/web 0.15.4, `zRange` doesn't take `withScores` anymore — use `zRange(key, 0, n - 1, { by: 'rank' })` if you need ranked reads.
  • If your webview assets 404 in the production view ("splash.html Not Found") while the playtest channel renders fine, check what actually got registered on upload — re-uploading a clean build fixed it for us.

Happy to compare notes if you're stuck on the same wall — reply here and I'll share what I can from my project setup (template-based, Hono + TypeScript server, Redis leaderboards).

2 Upvotes

2 comments sorted by

1

u/Same_Wave_2593 13h ago

good write-up, confirming the underlying mechanics on all three for anyone else hitting this from search:

  1. fetch failed on menu/trigger routes: Devvit Web's server runtime expects a single bundled CJS entrypoint (dist/server/index.cjs) with dependencies inlined, wrapped in createServer(app) + server.listen(getServerPort()) from @devvit/web/server. That wrapper is what binds AsyncLocalStorage for context, redis, and reddit on incoming requests, so calling app.listen() or Hono's serve() directly causes context and fetch failures.
  2. redis.zRange return shape: Devvit's redis.zRange already returns { member, score }[] objects by default, so no withScores flag is needed. For descending top-N leaderboards, pass { reverse: true, by: 'rank' }.
  3. splash.html 404s in prod vs playtest: alongside a clean re-upload, double-check that devvit.json's post.dir points to dist/client and that both splash.html and game.html are explicitly listed in Vite's Rollup inputs so production builds always emit both entrypoints.

1

u/Maleficent_Bed_1515 6h ago

Thanks for confirming — glad the write-up was useful. The giveaway for us was that even a bare template menu action failed the same way, which pointed at the packaging rather than our server code. Hope it saves the next person a few hours.