Skip to content

.env loading aborts all commands when a .env in the working dir (or any ancestor) uses export-prefixed lines #13291

Closed

Description

@norandom

What is the issue?

What happened

As of v0.21.x, Dagger auto-loads .env files from the working directory and its ancestors ("inner"/"outer env files"). If any such file uses the extremely common export KEY=value convention, Dagger aborts the command with:

failed to load inner env file in <dir>: parse error: "export FOO=bar": not a bare assignment

(outer env file when the offending file is in an ancestor directory.) The command fails entirely — dagger init,
dagger call, dagger functions, etc. all refuse to run.

Environment

  • dagger v0.21.3 (image://registry.dagger.io/engine:v0.21.3) darwin/amd64
  • Reproduced on macOS; not platform-specific.

Impact / severity

  • An .env in $HOME or a parent project dir (common) breaks every Dagger command run beneath it.
  • There appears to be no flag or env var to disable env loading (dagger --help shows none), so the only
    workaround is editing/removing the unrelated file or dropping a shadowing bare-assignment .env in the working
    dir.

Suggested fixes (any one)

  1. Accept and strip a leading export when parsing dotenv lines.
  2. Downgrade unparseable lines/files to a warning instead of a hard error.
  3. Add an opt-out (e.g. --no-env / DAGGER_NO_ENV=1) and/or only load .env from the module/workdir, not arbitrary ancestors.

Workaround (for others hitting this)

Put a .env containing a bare assignment (e.g. DUMMY=dummy) in your working directory; Dagger loads the nearest file and stops walking up.

Dagger version

v0.21.x

Steps to reproduce

Reproduction

  mkdir /tmp/dagger-env-repro && cd /tmp/dagger-env-repro
  printf 'export FOO=bar\n' > .env
  dagger init --sdk=go --name=t --source=.dagger
  # => Error: ... parse error: "export FOO=bar": not a bare assignment

  Matrix (all else equal):

  ┌──────────────────┬────────┐
  │  .env contents   │ Result │
  ├──────────────────┼────────┤
  │ export FOO=bar   │ abort  │
  ├──────────────────┼────────┤
  │ export FOO="bar" │ abort  │
  ├──────────────────┼────────┤
  │ FOO=bar          │ ok     │
  └──────────────────┴────────┘

So the trigger is specifically the export prefix; bare assignments are fine.

Expected

export-prefixed lines are valid in the dotenv files most tools accept (direnv, set -a; . ./.env, many .env
loaders, and shell source). Dagger should either parse export KEY=value (ignoring the export keyword), or
skip/warn on lines it can't parse rather than aborting — especially for ancestor .env files that have nothing to
do with Dagger.

Actual

A single unrelated .env anywhere up the directory tree makes Dagger unusable in that subtree, with no way to
proceed.

Log output

See above

Activity

  1. added this to the v0.21.4 milestone on Jun 1, 2026
  2. self-assigned this
    on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions