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 not read so ${ENV_VAR} unusable in .yarnrc.yml #2724

Closed
lensbart opened this issue Apr 9, 2021 · 9 comments
Closed

.env not read so ${ENV_VAR} unusable in .yarnrc.yml #2724

lensbart opened this issue Apr 9, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@lensbart
Copy link
Contributor

lensbart commented Apr 9, 2021

Describe the bug

I’m sure I must be doing something wrong, but I can’t get yarn to read the environment variables in my .env file, causing any yarn command to throw the following error when ${ENVIRONMENT_VARIABLES} are used in .yarnrc.yml:

Usage Error: Environment variable not found (ENVIRONMENT_VARIABLES) in [...]/.yarnrc.yml (in [...]/.yarnrc.yml)

Could it be that I have to configure something? The docs don’t seem to mention so.

To Reproduce

Clone this example repo and run yarn: https://github.com/lensbart/yarn

  • macOS 11.2.3 (20D91)
  • Node v14.16.0
  • Yarn version 2.4.1

Note: I didn’t use Sherlock because I thought this might interfere with resolving the .env file

@lensbart lensbart added the bug Something isn't working label Apr 9, 2021
@merceyz
Copy link
Member

merceyz commented Apr 9, 2021

Yarn doesn't read .env files, it reads your environment variables from process.env.***

@merceyz merceyz closed this as completed Apr 9, 2021
@lensbart
Copy link
Contributor Author

lensbart commented Apr 9, 2021

Thanks for the (very) quick response. Could you suggest a recommended way to have the .env file made available to yarn via process.env.***? Usually I would use the dotenv package, but not sure how to do so via the CLI.

Thanks again!

@arcanis
Copy link
Member

arcanis commented Apr 9, 2021

Why not put them in your bashrc/zshrc/...?

@lensbart
Copy link
Contributor Author

lensbart commented Apr 9, 2021

Brilliant! Not only did this fix my problem, but I can get rid of my dotenv dependency as well. And that on a Friday evening!! 😁

@quisido
Copy link

quisido commented Aug 5, 2021

I still think this is valid. I don't want to put it in .zshrc because it only applies to the one repository, e.g. a secret/access key for pulling dependencies from a private registry. I may want to configure this differently for each repository. Yarn should support repo-specific environment variables.

@rszemplinski
Copy link

I still think this is valid. I don't want to put it in .zshrc because it only applies to the one repository, e.g. a secret/access key for pulling dependencies from a private registry. I may want to configure this differently for each repository. Yarn should support repo-specific environment variables.

I agree with this. I would rather have repo specific environment vars instead of global

@tavoyne
Copy link
Contributor

tavoyne commented Jan 1, 2022

I agree. Typical use case is for NPM auth tokens that may differ from a project to an other. It'd be great if Yarn could read the .env file before performing any logic, or at least let us opt in for that behaviour (e.g. by explicitly specifying a path to the file in question). Can try to work on a PR if it's a setting that you'd consider integrating @arcanis.

@slaesh
Copy link

slaesh commented Jan 4, 2022

@theoavoyne would love to see your PR coming :)

@tavoyne
Copy link
Contributor

tavoyne commented Jan 4, 2022

@slaesh #3938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants