You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parseEnv result properties order does not match order in input string #62736
How often does it reproduce? Is there a required condition?
100% of the time
What is the expected behavior? Why is that the expected behavior?
Lot's of systems support "expanding" variables, but the expansion happens in the order of the env variables in the file. So If my .env file looks like this:
PASSWORD="s1mpl3"
DB_PASS=$PASSWORD
Node ignores the order and it's impossible to accurately expand the results accurately using just the output of parseEnv - you would have to parse the original input string yourself, compute the order of the keys, then re-order the resulting object to match the correct order.
You can see that because the object properties are returned in a different order that defined, dotenv-expand cannot expand the DB_PASS correctly. Flipping the order allows for correct expansion:
It would be relatively easy to make this almost work (store a std::vector of names alongside the existing std::map, and iterate the vector instead of the map when initializing the JS object).
But: JS objects always have nonnegative integer keys first, and ordered. So node could be changed so you'd get { B: 'b', A: 'a' } in your sample, but you will never be able to get e.g. { B: 'b', 1: '1' }.
The real problem I'm facing is I can't reliably expand env vars parsed with parseEnv with any existing library - does it make sense to the add expansion support to node?
In the native code, there was a list or vector in the parseEnv function, so would be possible to expand them properly with the correct order at that point?
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
Activity
bakkot commentedon Apr 15, 2026
It would be relatively easy to make this almost work (store a
std::vectorof names alongside the existingstd::map, and iterate the vector instead of the map when initializing the JS object).But: JS objects always have nonnegative integer keys first, and ordered. So node could be changed so you'd get
{ B: 'b', A: 'a' }in your sample, but you will never be able to get e.g.{ B: 'b', 1: '1' }.aklinker1 commentedon Apr 15, 2026
Alright, that all makes sense to me.
The real problem I'm facing is I can't reliably expand env vars parsed with
parseEnvwith any existing library - does it make sense to the add expansion support to node?In the native code, there was a list or vector in the
parseEnvfunction, so would be possible to expand them properly with the correct order at that point?src: preserve dotenv key insertion order
github-actions commentedon Jul 20, 2026
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.