Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--env-file support in NODE_OPTIONS #51147

Open
afonsojramos opened this issue Dec 13, 2023 · 11 comments
Open

--env-file support in NODE_OPTIONS #51147

afonsojramos opened this issue Dec 13, 2023 · 11 comments
Labels
dotenv Issues and PRs related to .env file parsing feature request Issues that request new features to be added to Node.js.

Comments

@afonsojramos
Copy link

What is the problem this feature will solve?

Sometimes env files are used as config files, therefore it should be allowed to set an --env-file in NODE_OPTIONS, for example in the .npmrc file, so that it applies to all scripts of that specific project.

What is the feature you are proposing to solve the problem?

Allowing for the --env-file flag to be supported in NODE_OPTIONS.

What alternatives have you considered?

No response

@afonsojramos afonsojramos added the feature request Issues that request new features to be added to Node.js. label Dec 13, 2023
@MoLow
Copy link
Member

MoLow commented Dec 13, 2023

Well, that can raise many issues and confusion since you can define NODE_OPTIONS inside the env file

@afonsojramos
Copy link
Author

I see, but I see no other solution for project specific .env, right? Do we have a way of knowing where the NODE_OPTIONS are coming from? If so, just disabling it for the .env recursive case might be a way? 🤔

@anonrig anonrig added the dotenv Issues and PRs related to .env file parsing label Jan 18, 2024
@jsumners
Copy link
Contributor

jsumners commented Mar 28, 2024

Well, that can raise many issues and confusion since you can define NODE_OPTIONS inside the env file

Not really. Command line switches take priority over all other methods of defining the same values. Just ignore any NODE_OPTIONS in the env file when it is being loaded by --env-file. The current state of rejecting the option is frustrating and surprising.

@kireerik
Copy link

I think this was working before version 20.12.x (related issue: remy/nodemon#2194).

@remy
Copy link

remy commented Apr 22, 2024

I think this was working before version 20.12.x (related issue: remy/nodemon#2194).

Not a related issue. They've opened an issue that is not related to nodemon at all (just to prevent confusion for anyone else)

@anonrig anonrig closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
@anonrig
Copy link
Member

anonrig commented May 28, 2024

Closing since technically this is not possible with the current implementation.

@jsumners
Copy link
Contributor

jsumners commented Jun 8, 2024

Can you please highlight what makes it "technically impossible"?

@anonrig
Copy link
Member

anonrig commented Jun 8, 2024

Can you please highlight what makes it "technically impossible"?

With the current state it is not possible, I didn't say impossible :-)

To summarize, if you refactor how we load and initialize node options as well as env file, it is possible. although, i think it will make both implementations more complex with little gain. if you think you can land it, with less unmaintainability, PRs are welcome.

@jsumners
Copy link
Contributor

@anonrig you seem to have direct knowledge of why it is impossible. I am asking you to provide a summary of that knowledge. As a reader of this thread, there is nothing in it that tells me why it would be closed without being solved.

@anonrig
Copy link
Member

anonrig commented Jun 10, 2024

@anonrig you seem to have direct knowledge of why it is impossible. I am asking you to provide a summary of that knowledge. As a reader of this thread, there is nothing in it that tells me why it would be closed without being solved.

You're right. I'll write an in depth analysis of my thoughts when I have the time. Meanwhile, I'm reopening the issue.

@dartess
Copy link

dartess commented Nov 28, 2024

This seems to be the closest I have found to my task. Perhaps someone here can give me a hint?

I want to use --env-file (--env-file-if-exists tbh) together with running npm package. Moreover, I want to get this cross-platform and without using third-party packages.

I think I got closer to it with npx and here I am:

npx --node-options='--env-file-if-exists=.env' playwright test

node: --env-file-if-exists= is not allowed in NODE_OPTIONS

Perhaps there is another way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotenv Issues and PRs related to .env file parsing feature request Issues that request new features to be added to Node.js.
Projects
Development

No branches or pull requests

7 participants