How can I access `env.DB` in my Pages/Worker on production?

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
.
GitHub
Contribute to cjxe/nextjs-d1-drizzle-cloudflare-pages development by creating an account on GitHub.
Was this page helpful?
How can I access `env.DB` in my Pages/Worker on production? - Cloudflare Developers