dotenvx / dotenvx

a better dotenv–from the creator of `dotenv`

Home Page:https://dotenvx.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

--env-file flag collision for node 20

keoz-simon opened this issue · comments

Hey! I'm trying to implement dotenvx to my TypeScript project.

This is my desired command:
dotenvx run --env-file=.env --env-file=.env.test --env-file=.env.test.local --overload ...

In case .env.test.local or any other --env-file option is not present, dotenvx fails. I think native fs error bubbles up. I'd suggest and need for my case an option, that it doesn't fail if a file is not present. I think it's not mandatory to let it fail. What do you think?

thanks!

commented

i think you're right. it shouldn't fail. it should just warn. will patch up.

commented

what version are you on? looks like this behavior is already correct - warns on missing file:

Screenshot 2024-03-19 at 10 42 44 AM
CleanShot 2024-03-19 at 18 49 52@2x hm.. should be the same. It doesn't even logs any debug log but exits early with exit 9 sigkill.

btw: sorry, different github account, same person. The globally installed dotenvx is the same as in projects node_modules

commented

what node version are you using here? maybe there is a flag collision i need to look into.

@motdotla v20.11.1
Which one are you using? I could recheck with yours.
OS is macOS 14.3

yes, that's the issue. node@18-latest works. node@20.11.1 doesn't.

commented

we used --env-file because we like the principle of least surprise (keep in mind many devs use the binary rather than the npm install (in which case this is not an issue))

that said, to unblock you, use -f as the flag instead of --env-file. that should work.

i'll also reconsider the flag name.

If I didn't get you wrong: binary doesn't work too. But I'm totally with you using this flag name.

-f would be a good workaround. Maybe + warning in README.
nevertheless best solution would be no collision at all.
thanks for your work

commented

binary should work, but not the node_modules/.bin/dotenvx since it's still dependent on the running node version.

the binary (or brew) installs can be done via:

brew install dotenvx/brew/dotenvx
or 
curl -fsS https://dotenvx.sh/ | sh
commented

there is some chatter with the Node team that they will replace the error with a warning - which I hope and expect to see.

So until then, I'm adding this issue to a new FAQ:

https://github.com/dotenvx/dotenvx?tab=readme-ov-file#faq