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
If you create a .env file in a package and that .env has let's say EXAMPLE=foo and a main package has EXAMPLE=example and that main package includes foo, if you export the EXAMPLE from foo and try to print on the main repository it will print the EXAMPLE from the main and not the foo.
For example:
packages/foo/.env:
EXAMPLE=foo
packages/foo/src/index.ts:
import dotenv from "dotenv";
dotenv.config();
const { EXAMPLE } = process.env;
export const example = EXAMPLE;
This is going to export the EXAMPLE variable from the .env.
packages/api/.env:
EXAMPLE=api
packages/api/src/index.ts:
import { example } from "@monorepo/foo";
console.log(example);
The output from console.log should be foo but it outputs api
The text was updated successfully, but these errors were encountered:
Hi @zefexdeveloper, dotenv loads a single .env file from process.cwd(). The environment variables should contain deployment level values; if you have 2 packages that require those vars then it implies they should be deployed separately and they shouldn't depend on one another. Try putting boundaries between your packages and only require env vars from the outermost packages and pass them as arguments to the inner packages.
@NiGhTTraX You mean like in the foo package methods I require what I would have in a .env as arguments instead and put the variables on the .env of the api package? It makes sense.
Thank you very much.
If you create a
.env
file in a package and that.env
has let's sayEXAMPLE=foo
and a main package hasEXAMPLE=example
and that main package includesfoo
, if you export theEXAMPLE
fromfoo
and try to print on the main repository it will print theEXAMPLE
from the main and not thefoo
.For example:
packages/foo/.env
:packages/foo/src/index.ts
:This is going to export the
EXAMPLE
variable from the.env
.packages/api/.env
:packages/api/src/index.ts
:The output from
console.log
should befoo
but it outputsapi
The text was updated successfully, but these errors were encountered: