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

direnv: error .envrc or .env file not found #916

Closed
mhenrixon opened this issue Mar 29, 2022 · 15 comments · Fixed by doctaphred/direnv#2 or #941
Closed

direnv: error .envrc or .env file not found #916

mhenrixon opened this issue Mar 29, 2022 · 15 comments · Fixed by doctaphred/direnv#2 or #941
Labels

Comments

@mhenrixon
Copy link

Describe the bug
Since the latest upgrade direnv won't load my .env files anymore.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade to latest version
  2. Try to use direnv

Expected behavior
I was expecting my .env files to be loaded

Environment

  • OS: macOS latest
  • Shell: fish
  • Direnv version: 2.31.0

Additional context

direnv allow .env
direnv: error .envrc or .env file not found

The file is there but it won't load. Someone said I now need to use fish syntax in my .env file which for shared project configuration in a multi-user repository just isn't feasible. direnv ends up being completely unusable unfortunately. Even if I move the changes to a .envrc they aren't loaded.

@mhenrixon mhenrixon added the Bug label Mar 29, 2022
@zimbatm
Copy link
Member

zimbatm commented Mar 29, 2022

Unfortunately, I had to make that feature optional as it was breaking back-compat for most users.

There is a new config option that you can use to toggle that feature back on: https://direnv.net/man/direnv.toml.1.html#codeloaddotenvcode

[global]
load_dotenv = true

@mhenrixon
Copy link
Author

brew extract --version=2.30.2 direnv homebrew/cask
brew install direnv@2.30.2

Also does the trick, not even putting the configuration inside a .envrc works for me. I've tried both bash syntax and fish syntax but it errors regardless. No environment variables are added to my shell anymore.

@zimbatm
Copy link
Member

zimbatm commented Mar 29, 2022

The configuration should be added to ~/.config/direnv/direnv.toml

@binderup
Copy link

I also spend some time today trying to figure out why direnv had stopped working for me.

Creating a config file as described above with the load_dotenv value reenabled the previous functionality (for me at least).

@knowsuchagency
Copy link

I think this ought to be made more prominent in the docs or even the homepage. I'm willing to bet most Mac users are going to run into this and some may not make it so far as this issue before giving up. I almost did

@judy
Copy link

judy commented Apr 7, 2022

This is a very frustrating issue.

  • If your copy of direnv updates, it silently doesn't load the environment variables.
  • Once you discover they're not loading (or you discover the same way I did by changing a value in your .env file and noticing that direnv isn't asking you to run direnv allow any more). The error message still says direnv: error .envrc or .env file not found, even though I'm staring at my .env file in the same folder and there are no weird permissions on it.

There's zero indication that a default value changed behind the scenes, for those of us that come to rely on this tool.

@zimbatm
Copy link
Member

zimbatm commented Apr 11, 2022

Yeah, sorry about the back-and-forth. I made a mistake. The point on the error message is also a good one if anybody wants to send a PR?

@dreki
Copy link

dreki commented Apr 13, 2022

This should've been a major version bump.

@1Mark
Copy link

1Mark commented Apr 13, 2022

This also broke for zsh
mv .env .envrc worked but this isn't obvious.

emilford added a commit to emilford/dotfiles that referenced this issue Apr 19, 2022
Direnv added a setting to opt in to loading .env files alongside .envrc
files, which caused a regression in behavior for those who were relying
on this functionality. Since some projects still use .env to manage the
environment, opt in to the previous behavior.

direnv/direnv#916
@anshajk
Copy link

anshajk commented Apr 23, 2022

Thankfully found this issue and was able to fix my own environment by adding it to ~/.config/direnv/direnv.toml

doctaphred added a commit to doctaphred/direnv that referenced this issue May 4, 2022
Follow-up on direnv#845 and direnv#911: resolves direnv#916

This commit simply updates the error messages and documentation to more
accurately reflect the current opt-in configurable handling of `.env` files.
@doctaphred
Copy link
Contributor

Yeah, sorry about the back-and-forth. I made a mistake. The point on the error message is also a good one if anybody wants to send a PR?

@zimbatm How'd I do? :) #941

@zimbatm
Copy link
Member

zimbatm commented May 11, 2022

Perfect, thanks a lot :) Just waiting on the CI to get green and then it can be merged.

@judy
Copy link

judy commented May 11, 2022

@doctaphred Much appreciated, I think this will be a great solution to the complaint I raised earlier. I don't read/write Go either, so I can't comment on the PR, but the language looks perfect.

zimbatm pushed a commit that referenced this issue May 11, 2022
Follow-up on #845 and #911: resolves #916

This commit simply updates the error messages and documentation to more
accurately reflect the current opt-in configurable handling of `.env` files.
@kris-luminar
Copy link

mv .env envrc

it was .envrc for me, not envrc

@1Mark
Copy link

1Mark commented Jul 14, 2022

mv .env envrc

it was .envrc for me, not envrc

Typo, original message fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10 participants