GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing github.com — src: make `--env-file` return warning when not found by anonrig · Pull Request #53177 · nodejs/node Conversation
|
|
Review requested:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
dotenv return warning when not found--env-file return warning when not found
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think #50588 got this right. Node should error if the user tells it to load a file that doesn’t exist. That’s what we do for --require, --import and the the other commonly used flags that tell Node to load a file. I understand that this may differ from dotenv‘s behavior, but we need our CLI to be internally consistent with itself, not with other tools. Generally we error when a specified file cannot be found.
I am also not convinced that “I need to run the same command to start Node for development and for production” is a good idea, much less a use case that we want to support at the expense of some users not getting useful errors, for example if a production server expects an .env file that is missing but the service starts up anyway. Users who really want to run the same command for development and production can handle this in many ways outside of Node’s scope, such as running the equivalent of touch .env before starting Node.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am +1 on this change if it is semver-major.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This requires documentation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@MoLow The feature is under |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@targos Can you review again? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don’t feel strongly enough about this to block it, but I want @nodejs/tsc to review so that we get a broader opinion of what we think the desired UX should be: either this PR’s warning or the current behavior’s error or the opt-in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sounds good to me 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I wont block but I'm -1 on this change. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
While I agree that errors should be preferable, I think establishing a pattern is also important.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm +1 on this change, having used this option a couple of times for internal scripting, all I really want is an optional way to opt-in to using a .env file while still allowing the same script to be run if someone else in the team wants to run the same script and no file is available in their machine.
I want it to be optional so that it can still be codified into package.json scripts or bash aliases.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
What if they all threw a warning, and a new flag, like --throw-on-file-not-found (or similar) would cause them to instead throw. Same for this flag |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I'm fine with landing it, we should probably discourage production use, and explicitly mention that is a development tool and using in production might cause side effect if you forget to configure it properly |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The TSC discussed this in the TSC meeting today and there were no blockers so this can land. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I don't know what the main use case for If folks use this flag in production, then I strongly believe that ignoring user errors by default is a mistake. Also, the behavior of this flag was changed specifically because users requested the current behavior (i.e., an error), and both polls mentioned above resulted in the majority of respondents saying that they'd expect an error. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would prefer having that configurable (i.e. having a flag to override the default behavior). Once we have that other flag, this PR can then propose flipping the default of this other flag if it has consensus. I'm happy to help making that happen (related: #53060 (comment)).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
If we’re going to have two flags, I think it’s much more useful to have a flag for each behavior. Then you can have a required node --env-file=base.env --env-file-optional=local.env app.js |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@tniessen dotenv is mostly used on development not on production. env-file is also aimed to be used for development environment. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
And what size would that be? #53177 (comment) has 27 votes, and |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hey there, author of #53060 here. I wasn't subscribed to this thread, so I hadn't seen any of this until now, sorry. Seeing as the TSC didn't reach any consensus, and the outcome was "discuss it async in the PR", I'm adding my 2 cents. Honestly, it seems clear to me the majority of users expect an error to be thrown - the 2 polls ran showed >60% of voters picking it. I personally agree with @GeoffreyBooth and prefer that option. If I'm not mistaken, proposed solutions boil down to This throwing an error if file doesn't exist (current behaviour): This showing a warning if file doesn't exist but executing anyways (this PR): Adding a new flag Adding a new flag to this PR that can toggle "strict mode" (not implemented): Obviously I favour the 3rd approach, as it is the least disruptive (not that it matters at this point, feature is experimental after all) and allows for the highest freedom with the least setup (no duplication of scripts in Maybe we could add a warning if the file doesn't exist and was marked as optional as @jasnell proposed, appeasing that crowd too? It doesn't atm. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Also, my PR was approved by @mcollina but is blocked by @anonrig. Not sure up to what degree there is a "conflict of interest" here. I do agree Node collaborators' input should be regarded more highly than the general public, but in this case one could argue my PR is also ready to land, so I'm not sure if that's a strong argument in favour of this one in this regard; we're kind of at a stalemate. On a side note, I'm surprised at the amount of discussion such a small change sparked and I'm happy to see such a thriving community chime in and do their best to improve such a widely used tool! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@anonrig would you be willing to drop your block on #53060? It seems that the majority of users would prefer the error behavior, but we have a substantial minority that want the warning behavior, so I think the reasonable thing to do would be to land #53060 to satisfy both constituencies. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Here's my personal thoughts on this: Most people have @GeoffreyBooth I still don't think we should maintain 2 separate CLI flags for a development specific functionality. When we first merged If you still insist, I'd like @nodejs/tsc to take a vote on this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
My personal preference is the status quo so I'm fine with neither PR landing; but I won't block. I think we should respect our user feedback. If we build this feature at all, it should do what users want. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@anonrig I totally see your point here, but anecdotal evidence is a tough sell:
For example I've never seen such a setup, rather most code I've seen made use of
No need - they can just use the optional flag and keep everything else as is:
These are 2 very fair points I'll concede to. My implementation is objectively more complex, and having a
I agree, but as @GeoffreyBooth said, I'd like to also somehow take users' desires into account. We're never going to get 100% of Node users to vote on such a small issue (or any for that matter), but we should take action somehow. We either
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
For what it’s worth, this is possible already: import { readFile } from 'node:fs/promises' import { parseEnv } from 'node:util' try { const envFileContents = await readFile('.env', 'utf8') parseEnv(envFileContents) } catch {} The one thing this doesn’t do is affect Node itself if there’s a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Seeing as my PR has received two -1s at this stage, I'm personally ok with merging this one in favour of at least improving the current situation, even if it goes against the polls. We can always revisit later with more feedback |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
FWIW, we have revisited the feature, which originally only produced a warning. Then, based on more feedback, it was changed to the current behavior. Recent polls, albeit with a small sample size, also indicated that this was preferred by (some subset of) the community. So I am not convinced that merging this PR would actually improve on the status quo. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
@tniessen Fair point. Hoewver, it does force users to either have duplicated scripts (one with, the other without |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@tniessen Why can't we support both options? Throwing a non-negligible subset of the community under the bus would be a fairly questionable approach. This doesn't seem to be the kind of a feature that benefits from being opinionated, especially having in mind that, as @anonrig has pointed out, .env is very frequently used in non-prod environments. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@kibertoad I don't think I've said anything against supporting both options. (Or perhaps I did a long time ago and don't remember.) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I'd like to add a new dimension to the discussion from a frontend/full-stack perspective. While I agree with @anonrig's argument that .env files are not used in production environments, this is generally prevalent in the backend world of Node.js. As you might know, on the frontend side, popular tools like Vite and Next.js process environment files with slightly different dynamics. In such codebases, helper scripts or code pieces may need to leverage the References:
Therefore, in a use-case where small scripts are utilized to trigger Prisma/ORM migrations (especially the rise of server-side rendering made full-stack codebases quite popular), we might need to use commands like I may have expanded the scope a lot... but I thought it should be considered when making a decision. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing given the recent TSC vote: https://github.com/nodejs/TSC/blob/main/votes/2024-06-25-0.json |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Fail for missing env file in development only Add--env-file-if-exists
There was an error while loading. Please reload this page.