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 verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Fri Jul 5 17:56:41 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 8
Binaries:
Node: 20.12.0
npm: 10.5.0
Yarn: 1.22.19
pnpm: 9.7.0
Relevant Packages:
next: 14.2.6 // Latest available version is detected (14.2.6).
eslint-config-next: 14.2.6
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.4
Next.js Config:
output: standalone
Which example does this report relate to?
none
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
cannot set env variables in run time, all env, not only the one that start with NEXT_PUBLIC_ are embedded in process.env in build time and cannot be changed.
Expected Behavior
be able to pass server env variables in run time.
To Reproduce
https://github.com/galgue/nextjs-runtime-env/tree/main
run npm run build
go to .next/standalone folder and run RUN_TIME=1 node server.js
in the browser browse into http://localhost:3000/api/health to get the env variable.
expect to see RUN_TIME=1 but we get undefined.
The text was updated successfully, but these errors were encountered:
Hi there -- thanks for the report. This is happening because Next.js is pre-generating your /api/health route at build time because there wasn't any indication that you needed to access dynamic data.
We changed this in Next 15 / canary, so route handlers are no longer cached by default. However in versions prior to 15, you'd need to add this to the top of your route handler to ensure it's always executed at runtime:
exportconstdynamic="force-dynamic"
You should then see the RUN_TIME environment variable in your API endpoint.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.6.0: Fri Jul 5 17:56:41 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6000 Available memory (MB): 32768 Available CPU cores: 8 Binaries: Node: 20.12.0 npm: 10.5.0 Yarn: 1.22.19 pnpm: 9.7.0 Relevant Packages: next: 14.2.6 // Latest available version is detected (14.2.6). eslint-config-next: 14.2.6 react: 18.3.1 react-dom: 18.3.1 typescript: 5.5.4 Next.js Config: output: standalone
Which example does this report relate to?
none
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
cannot set env variables in run time, all env, not only the one that start with NEXT_PUBLIC_ are embedded in process.env in build time and cannot be changed.
Expected Behavior
be able to pass server env variables in run time.
To Reproduce
https://github.com/galgue/nextjs-runtime-env/tree/main
run
npm run build
go to .next/standalone folder and run
RUN_TIME=1 node server.js
in the browser browse into
http://localhost:3000/api/health
to get the env variable.expect to see RUN_TIME=1 but we get undefined.
The text was updated successfully, but these errors were encountered: