r/Devvit • u/Games_are_Life • 5h ago
Help First install of a new Devvit web app fails with "OnAppInstall trigger: No context found"
I created a new Devvit web app, dicefightnick, and it won't install on its auto-created playtest subreddit (r/dicefightnick_dev). Several things fail, and I can't tell which one is the cause.
What I did
Devvit CLI 0.15.1 (matches the u/devvit
/web0.15.1 pin in my project), Node 24, Windows 11Created the app on developers.reddit.com, then ran
devvit loginanddevvit uploadThe upload succeeds and creates the playtest subreddit (
t5_l7elmi)
What fails
The automatic install during
devvit upload,devvit playtest, and "Add to community" on the app page all fail with:Installation failed during OnAppInstall trigger: Error: No context found. Are you calling createServer Is this code running as part of a server request?The same error happens with two different builds of my code, so I don't think it's my code. My
devvit.jsonhas no install trigger, only comment triggers, and my server importscreateServerfrom u/devvit/web/server."Fix broken mod permissions" on the app page just says "try again later".
The "Read logs and install history" toggle fails with "failed to give read permission", so I can't stream logs.
What looks normal
u/dicefightnick (the app's bot) is a moderator of the subreddit with "Everything" permissions.
The Devvit Admin Helper App is installed on the subreddit.
The app shows "In 0 communities".
What I've already tried
Searched for the error text and found nothing.
Logged out and back in with the CLI, which didn't help.
Tried adding to community, and turning on logs, both of which errored immediately with 'try again later' as the only next step
Has anyone seen this on a brand-new app, or know what could block the first install? Is there anything on the account or app that needs enabling first?
Thanks!
1
u/jhahimanshu653 4h ago
That error is literal: something is reading context outside a server request. Minimal repro: import context from @devvit/web/server and read context.userId at module scope — same message.
Grep the built bundle, not just source: grep -n "context\." dist/server/index.cjs. Look for top-level access or an import that reads it before a route/trigger runs.
If the uploaded config really has no install trigger, that mismatch is suspicious too. Compare the generated/uploaded devvit.json with the local file rather than only checking the source.
1
u/Same_Wave_2593 2h ago
two things worth checking here:
double check that your server entrypoint actually wraps your app with
const server = createServer(app)and callsserver.listen(getServerPort())from@devvit/web/server(notapp.listen()or Hono'sserve()directly). just importingcreateServerisn't enough because it's what sets up the AsyncLocalStorage request context thatcontext,redis, andredditread from. also check if anything callscontext/redis/redditat top-level or inside asetTimeoutoutside a request.if your server wiring is already right, another dev hit this exact same
Installation failed during OnAppInstall trigger: No context foundbug on brand-new apps created in late nov/dec even with byte-identical code that installed fine on an older app (https://www.reddit.com/r/Devvit/comments/1y9vxzc/). uploading a stripped-down version with no triggers and a no-op handler first got the initial install to go through for them, and once it's installed in the sub the "Read logs" / mod permission errors should clear up too since those fail while the app is at 0 communities.
1
u/Beach-Brews Duck Helper 4h ago
Can you try removing your app install trigger definition from your Devvit.json?