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
Disable loading .env files #14010
Comments
I tried investigating the source, and the |
Narrowed it down to two methods My test so far has been to install Nx locally and run a dummy command like Project.json: {
"name": "dummy",
"targets": {
"jump": {
"executor": "nx:run-commands",
"options": {
"commands": ["echo $MY_VAR"]
}
}
}
} Root level .env:
What I am after in this test is when echoing I should see nothing, not the env var loaded from the .env file. |
Got it. PR incoming. |
+1. This completely breaks Vite's env setup since Vite doesn't override existing env variables. So nx loads the default The only solution for now I think is to rename my start script to |
I think what we might want to do is add an option in That way, users generating a Vite project will have this set and handled for them automatically. The environment variable can still be added and documented here https://nx.dev/reference/environment-variables#environment-variables for users who may need the behavior for some projects in their workspace. |
Another option I could think of is nx only loading I think the current setup would also conflict w/ Create React App, but seems that's getting left behind so not a big deal there |
Loading a subset of |
Loading only a subset would also be a pretty major breaking change when compared to the functionality thats been around for a long time now |
are there any workarounds to avoid nx loading |
+1, this even breaks one of the Nx recipes to build your own executor to compose executors: https://nx.dev/plugins/recipes/compose-executors because when the executor is executed also loads the env vars for |
AFAIK you can't avoid loading .env by nx yet but you can undo what nx loaded (before running unset ${!VITE_*} |
Hi! I just switched from vite -> nx/vite and environment variables loading is quiet broken, loading order is inversed and some files are not loaded at all (.env.development.local). Another problem is that variables replacement does not work anymore (dotenv extended is probably not used) Is there some quick temporary solution to run on the vite.config.js file? Maybe resetting the env before loading the new one? |
This seems to be fixed, but it is not well documented #12602 |
The only option I found is to patch nx with pnpm and replace all |
What the current state looks like:
Essentially it seems that the reason for the flag not working is because where this flag should be provided, it is not. When this issue gets fixed, this flag should be described in the docs Currently resolved it for myself similarly to @edikdeisling, where I replaced the default |
Any news regarding this issue? Will it be worked on after NX 18 (crystal) has been launched? I recently migrated a monorepo with a few Serverless (Framework) projects. They rely on the When running the deploy command via e.g. "nx deploy" it would never succeed because What I did (not future proof as mentioned before) is patching
NX_LOAD_DOT_ENV_FILES could be an option, but |
Description
Be able to opt out of loading .env files.
Motivation
When attempting to migrate our monorepo to use Nx, we have encountered a challenge where our existing .env files are causing tests to fail because they are loaded when we originally didn't intend them to load during tests.
Suggested Implementation
If an environment variable is present like
NX_LOAD_DOT_ENV_FILES
and set to"false"
then no .env files will be loaded.Another possibility is to check if an env file has been ignored in the .nxignore file. This would allow removing all or only a few env files from the load hierarchy.
The text was updated successfully, but these errors were encountered: