-
Notifications
You must be signed in to change notification settings - Fork 26.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standalone build does not include server-side variables from .env.local
#46296
Comments
Having this issue at the moment. Have you found a workaround? |
I have not, unfortunately. In my case, I luckily could get by with using just .env |
Yes I did the same on before build i copy files to .env and temp delete the other files. This is also a affects .env.test. |
With this answer I was able to access my environment variable inside my docker container. What I did: Add my environment variables as docker build arg
Define ENV variable in Dockerfile
Use global.process.env instead of process.env global.process.env.API_URL_1 |
I have experienced this issue - public variables from .env.local are inlined into the build perfectly fine, but the server-side variables are missing from the resultant .env file which is bundled with the build. The workaround I've found is to simply copy the .env.local file to the build folder. In the case of your repo, copying to the app folder of the runner stage in Dockerfile (this is how mine is set up too). It seems like env files are still picked up by a build at run time. |
I'm also having this issue. |
Hey all, same for .env.test |
This comment has been minimized.
This comment has been minimized.
I ran into the same issue with my GitHub Actions CI. I've created the env file in the CI itself:
|
This is still an issue in 2024. If you do not precede all of the variables names with NEXT_PUBLIC the variables will not be available on the server. This leaves the SSR feature of storing secrets on the Next.js server completely unusable. This must be fixed as soon as possible. It is important to notice that this is an issue not only for environment variables defined in the .env file, but also for environment variables that are passed to next build command. Doing: MY_VARIABLE=my-variable-value next build Does not work neither, using |
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103
Binaries:
Node: 18.13.0
npm: 8.19.3
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.1.7-canary.28
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
Standalone mode (output: "standalone")
Link to the code that reproduces this issue
https://github.com/evakkuri/nextjs-standalone-envvar-bug
To Reproduce
docker build -t nextjs-standalone-envvar-bug:latest .
.env
and.env.local
filesdocker run -p 3000:3000 nextjs-standalone-envvar-bug
http://localhost:3000
process.env.API_URL_1
is undefined, and all other environment variables are defined as expectedDescribe the Bug
Standalone build does not include server-side environment variables from
.env.local
, at least with the Dockerfile as per NextJS example.Expected Behavior
Also
process.env.API_URL_1
should have retrieved a value from.env.local
, indicating that server-side variables are read at build-time from.env.local
.Which browser are you using? (if relevant)
Firefox 110.0 (64-bit)
How are you deploying your application? (if relevant)
Dockerfile (included in repo)
The text was updated successfully, but these errors were encountered: