Environment variables load order
Unanswered
Alapaha Blue Blood Bulldog posted this in #help-forum
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!
Thanks!
5 Replies
@Alapaha Blue Blood Bulldog 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!
.env.local gets checked AFTER env.$(NODE_ENV).localThis effectively means your .env.development.local is going to be checked before .env.local
.env.local is more like a sample environment variable file.
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
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
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