Before shipping code to users, you need to ensure the optimized production build works flawlessly. You do this by running: npm run build npm run start Use code with caution.
// Validate and parse the environment export const env = envSchema.parse(process.env);
This comprehensive guide covers how .env.local.production fits into the environment variable hierarchy, when to use it, and how to manage it securely. The Environment Variable Hierarchy
NODE_ENV=staging vite build
If you rely on .env.local.production and then migrate frameworks, your build will silently fail to load configuration.
Across most frameworks, the general rule of precedence is the same:
# Environment variables .env .env.local .env.*.local .env.production .env.production.local .env.local.production
Below is a typical setup for a production environment. You should replace the placeholder values with your actual live credentials.
docker run --env-file ./docker/prod-override.env myapp:latest
The file .env.local.production is used exclusively for local debugging of production builds. It is ignored by Git. Do not use this file in CI/CD pipelines. Before shipping code to users, you need to
CRA is more rigid. It uses react-scripts and has limited support.
The difference is purely syntactical. Most modern frameworks prefer the former ( env.production.local ), but legacy systems or custom CI/CD pipelines might recognize the latter.
A typical precedence order from lowest to highest looks like this: docker run --env-file
On platforms like Vercel, you never use .env.production.local . You use their dashboard or CLI: