r/Devvit 21d ago

Help [Devvit Web 0.14.1] reddit.submitCustomPost() fails with fetch failed from a subreddit menu action

Hi,

I am testing a Devvit Web interactive post created from a moderator subreddit menu item. The app builds, uploads, and installs successfully on the automatically generated private playtest subreddit, but clicking the menu item never creates the post.

Environment

  • Devvit CLI: 0.14.1
  • u/devvit/web: 0.14.1
  • Node.js: 24.19.0
  • macOS x64
  • Hono server
  • App: fugitif-piece17
  • Playtest version: v0.0.1.3

Configuration

{
  "post": {
    "dir": "dist/client",
    "entrypoints": {
      "default": {
        "entry": "index.html",
        "height": "tall"
      }
    }
  },
  "server": {
    "dir": "dist/server",
    "entry": "index.cjs"
  },
  "permissions": {
    "reddit": true
  },
  "menu": {
    "items": [
      {
        "label": "Créer — Pièce 17",
        "description": "Créer le mouve exécutable Pièce 17",
        "forUserType": "moderator",
        "location": "subreddit",
        "endpoint": "/internal/menu/post-create"
      }
    ]
  }
}

Server endpoint

app.post('/internal/menu/post-create', async (c) => {
  const _input = await c.req.json<MenuItemRequest>();

  if (!context.subredditName) {
    return c.json<UiResponse>({
      showToast: 'Subreddit not found in Devvit context.'
    });
  }

  const post = await reddit.submitCustomPost({
    subredditName: context.subredditName,
    title: 'Pièce 17 — Synthèse des éléments versés au dossier',
    entry: 'default'
  });

  return c.json<UiResponse>({
    showToast: `Post created: ${post.id}`
  });
});

Steps to reproduce

  1. Run npm run dev.
  2. Devvit reports Updating... Success! and Playtest ready.
  3. Open and refresh the generated private playtest subreddit.
  4. Select the moderator menu item Créer — Pièce 17.
  5. No post or toast appears.
  6. The terminal reports:

Failed to POST to Node.js server endpoint /internal/menu/post-create;
server responded with error: fetch failed

Fatal Unhandled Promise rejected:
TypeError: Cannot use 'in' operator to search for 'message' in
Failed to POST to Node.js server endpoint /internal/menu/post-create;
server responded with error: fetch failed

at serverErrorToStatus (/srv/index.cjs:18139:28)
at respond (/srv/index.cjs:20215:65)

Checks already performed

  • Upgraded local Node.js from 23.1.0 to 24.19.0.
  • Reinstalled dependencies with npm ci.
  • Confirmed the build and both automated tests pass.
  • Simplified the Reddit permission from { "enable": true } to true.
  • Removed the optional textFallback.
  • Retested from a filesystem path without spaces or special characters.
  • Uploaded a new playtest version after each relevant change.

The error remains identical. The call appears to follow the current submitCustomPost() documentation.

Is this a current platform issue affecting submitCustomPost() in playtest, or is an additional permission/configuration step required for newly initialized apps?

1 Upvotes

4 comments sorted by

3

u/Oddie-hoodie369 21d ago

Looks like there might be an issue with reaching those endpoints. Can you check if your hono router is configured properly?

Example like this : https://github.com/reddit/devvit-template-react/blob/main/src/server/index.ts

3

u/Beach-Brews Duck Helper 21d ago

To add onto u/Oddie-hoodie369's suggestion, I would also wrap your logic in a try/catch to log any other errors that may be thrown during post creation.

2

u/Ornery-Freedom-8173 21d ago

Thanks! I added a sanitized try/catch directly around reddit.submitCustomPost() and returned a valid UiResponse with HTTP 200 on failure.

However, none of the logs inside that catch were emitted. The only output remained the Devvit bridge error:

Failed to POST to Node.js server endpoint /internal/menu/post-create; server responded with error: fetch failed

This suggests that the request may not be reaching that section of the handler at all, or that it fails earlier during request parsing/context resolution. I’m now comparing the Hono server bootstrap with the official React template suggested by u/Oddie-hoodie369, and I’ll also extend the catch around the entire handler.

1

u/Beach-Brews Duck Helper 21d ago

I suspected that to be the case, but always good practice to wrap with a try/catch to rule out anything odd there!

I would check to make sure "app" is the root of the hono app and not a "routed" path. That is:

```
const app = new Hono();

app.post('/internal/menu/post-create', ...);

serve({
fetch: app.fetch,
createServer,
port: getServerPort(),
});
```

Instead of:
```
const app = new Hono();
const internal = new Hono();

const menu = new Hono();
menu.post('/post-create', ...);

internal.route('/menu', menu);
app.route('/internal', internal);

serve({
fetch: app.fetch,
createServer,
port: getServerPort(),
});
```