Next.js Discord

Discord Forum

Environment variables load order

Unanswered
Alapaha Blue Blood Bulldog posted this in #help-forum
Open in Discord
Alapaha Blue Blood BulldogOP
Hello! According to the documentation (https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order) it seems that if I have a same variable defined in the .env.development and .env.local it should prefer the value in the .env.local if I run a development mode. For some reasin it still reads it from the .env.development. Any ideas why?

Thanks!

5 Replies

Alapaha Blue Blood BulldogOP
But I do not have .env.develpoment.local I have .env.develompent only. As I understand this list should be read from bottom to top if the same variable exist.

1. process.env
2. .env.$(NODE_ENV).local
3. .env.local (Not checked when NODE_ENV is test.) <-- SAME VARIABLE HERE (sholdn't it prefer that?)
4. .env.$(NODE_ENV) <-- SAME VARIABLE HERE (.env.development)
5. .env
Or if I read it from top to bottom:

1. process.env
2. .env.$(NODE_ENV).local <-- DOES NOT EXIST IN MY REPO
3. .env.local (Not checked when NODE_ENV is test.) <-- SAME VARIABLE HERE (sholdn't it prefer that?)
4. .env.$(NODE_ENV) <-- SAME VARIABLE HERE (.env.development)
5. .env