Hi community!
I’m currently struggling with environment variables settings with nextjs standalone output.
The standalone output copies .env file despite outputFileTracingExcludes set in next.config.ts.
Any one having the same issue?
Current
-
Next.js standalone mode copies
.envfiles to the output directory -
outputFileTracingExcludesdoesn’t prevent this behavior -
This creates security issues for Docker deployments where secrets get baked into images
-
Workaround: manually delete
.envfiles post-build in Dockerfile
Expected
outputFileTracingExcludesshould exclude.envfiles from standalone output
I tried with next.config.ts:
output: "standalone",outputFileTracingExcludes: { "*": [ ".env", ".env.*", ".env.local", ".env.development", ".env.production", "**/.env", "**/.env.*", ],},