Next.js Discord

Discord Forum

How can I access `process.env.DB` on production?

Unanswered
Buff-collared Nightjar posted this in #help-forum
Open in Discord
Buff-collared NightjarOP
Steps to reproduce:
1. Clone https://github.com/cjxe/nextjs-d1-drizzle-cloudflare-pages
2. Follow README.md.
3. Run pnpm start or pnpm pages:prod.
4. Launch the web app using your favourite browser.

Error:
[Error: Failed to retrieve the Cloudflare request context.]
 [Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
  digest: '3614312654'
}


I don't get this error when I run on dev due to how next.config.mjs is set up, but I can't make this work on production. The main issue is the Cloudflare pages return an error when it tries running getRequestContext().env.DB in src/server/db/index.ts.

UPDATE: Solved on the Cloudflare Developers discord channel. https://discord.com/channels/595317990191398933/1242099084312182854/1242099084312182854

0 Replies