.env.local.production Now
Before you rush to create .env.local.production, understand the risks. This file sits in a difficult position between convenience and catastrophe.
GitHub Actions or GitLab CI often run next build in a production environment but need a build-time secret that differs from runtime. .env.local.production
# .github/workflows/deploy.yml
- name: Create .env.production.local
run: |
echo "BUILD_CACHE_TOKEN=$ secrets.CI_TOKEN " > .env.production.local
npm run build
You run:
echo "DATABASE_URL=postgres://prod_user:SuperSecret123@db.prod.com/mydb" > .env.production.local
git add . && git commit -m "Fix prod config"
git push origin main
Congratulations. You have just pushed your production database password to GitHub. Even if you delete it in a later commit, it lives in the commit history. Before you rush to create
Use this file for:
In many modern frameworks (like Next.js, Vite, and Gatsby), there is a specific hierarchy of file loading. While .env.production is loaded for production builds, .env.local.production acts as an override specifically for local instances of a production build. Congratulations
It fits into the priority ladder like this (higher priority overrides lower):