Skip to content

Deno compile --env-file fails when specified file is not found #30402

@is-jonreeves

Description

@is-jonreeves

Version: Deno 2.4.4
OS: Windows 11 Pro

Steps

  1. Create a src/index.ts file and DO NOT create .env.missing
  2. Run deno compile --allow-net --allow-env --env-file=.env.missing --output=./dist/app src/index.ts

Expected

Successfully build a binary

Actual

Task build deno compile --allow-net --allow-env --env-file=.env.missing --output=./dist/app src/index.ts
Warning The `--env-file` flag was used, but the environment file specified '.env.missing' was not found.
Compile file:///C:/Users/jon/projects/example/src/index.ts to ./dist/app.exe
Warning Environment variables from the file ".env.missing" were embedded in the generated executable file
error: Writing deno compile executable to temporary file './dist\app.exe.tmp-4f6be2f87253cac0'

Caused by:
    0: path not found
    1: path not found

Workarounds

If I go ahead and create the .env.missing file, then deno compile works fine.

Context

I was looking for a way to do dotenv style env file inheritance (based on development/production) and noticed the following worked fine with deno run but not deno compile:

// ✅ Success
deno run --allow-net --allow-env --env-file=.env --env-file=.env.development --env-file=.env.development.local --watch src/index.ts

// ❌ Failure
deno compile --allow-net --allow-env --env-file=.env --env-file=.env.production --env-file=.env.production.local --output=./dist/app src/index.ts

Usually I use .env, .env.development and .env.production as defaults that are committed into the repo, and then rely on .env.*.local files at dev-time or build-time, to layer in any further values. At run-time, local ENVs would still be expected to override/set any values. This all appears to work as expected except for the failure to build when an --env-file is not found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerelated to the `deno compile` featureneeds discussionthis topic needs further discussion to determine what action to takeneeds investigationrequires further investigation before determining if it is an issue or not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions