You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've migrated my Next.js from Vercel to Cloudflare, but now I have a serious issue. How can I access environment variables in the API router? On Vercel, I only needed to configure them in the project, and then I could access them via process.env. However, in Cloudflare, there are numerous methods (such as Environment, KV), and I've tried them all, but I still can't access the environment variables.
I try const kvNamespace = (process.env as unknown as CloudflareEnv).DOMAIN_PRICE but got {}
try getRequestContext().env still got {}
does anyone can tell me how can I access env variable conveniently?
Reproduction
No response
Pages Deployment Method
Pages CI (GitHub/GitLab integration)
Pages Deployment ID
No response
Additional Information
No response
Would you like to help?
Would you like to help fixing this bug?
The text was updated successfully, but these errors were encountered:
You should be able to access your variables by using the getRequestContext utility (and also with process.env although getRequestContext is the recommended way)
My guess here is that you're not setting up the variables correctly?
Where are you not seeing your variables? locally? or also in the deployed application? both?
if you don't see them locally you need to set them in a wrangler.toml file (or secrets, that should not be committed, in a .dev.vars file)
if you don't see them in the deployed application:
if your wrangler.toml file is used for deployments (meaning that it has the pages_build_output_dir field) again you need to make sure that the toml file contains the variables
if no wrangler.toml file is used for deployments (i.e. you don't have a toml file or it you have one but it doesn't specify the pages_build_output_dir field) then you need to set the variables (or secrets) in the Cloudflare dashboard (secrets always need to be specified in the dashboard or handled via the wrangler pages secret command)
next-on-pages environment related information
System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103
CPU: (8) arm64 Apple M1
Memory: 16 GB
Shell: /bin/zsh
Package Manager Used: pnpm (8.11.0)
Relevant Packages:
@cloudflare/next-on-pages: 1.11.1
vercel: N/A
next: 14.1.4
Description
I've migrated my Next.js from Vercel to Cloudflare, but now I have a serious issue. How can I access environment variables in the API router? On Vercel, I only needed to configure them in the project, and then I could access them via process.env. However, in Cloudflare, there are numerous methods (such as Environment, KV), and I've tried them all, but I still can't access the environment variables.
I try
const kvNamespace = (process.env as unknown as CloudflareEnv).DOMAIN_PRICE
but got {}try
getRequestContext().env
still got {}does anyone can tell me how can I access env variable conveniently?
Reproduction
No response
Pages Deployment Method
Pages CI (GitHub/GitLab integration)
Pages Deployment ID
No response
Additional Information
No response
Would you like to help?
The text was updated successfully, but these errors were encountered: