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

Package not respecting dotenv file scope #17

Closed
theprobugmaker opened this issue Aug 25, 2020 · 2 comments
Closed

Package not respecting dotenv file scope #17

theprobugmaker opened this issue Aug 25, 2020 · 2 comments

Comments

@theprobugmaker
Copy link

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

@NiGhTTraX
Copy link
Owner

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.

@theprobugmaker
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants