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

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.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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

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

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

This should’ve been a major version bump.

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

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?

mv .env envrc

it was .envrc for me, not envrc

Typo, original message fixed.

mv .env envrc

it was .envrc for me, not envrc

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

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