Skip to content

Vite fails to read .env #3364

@Bloodiko

Description

@Bloodiko

TLDR:

When running Fresh via Vite, the .env file is not properly loaded into the process.

Reproduction:

// .env file
CUSTOM="debug_value"

// vite.config.ts (to error out as soon as possible after reproduction) 
console.log(`CUSTOM env var from dotenvfile: ${Deno.env.get("CUSTOM")}`);
process.exit(1)

Running vite dev task:

deno task dev
Task dev vite
CUSTOM env var from dotenvfile: undefined

Additional Info

When running the file manually using deno run -A --env vite.config.ts
it works:

deno run -A --env vite.config.ts
CUSTOM env var from dotenvfile: debug_value

Assumption

This may be totally wrong, but I assume that vite runs the deno subcommand by using deno run -A FILE but is missing --env --> deno run -A --env FILE

Because adding

// in vite.config.ts
import "jsr:@std/dotenv/load";

to the file also works when using deno run -A FILE (by omitting --env)

deno run -A vite.config.ts      
CUSTOM env var from dotenvfile: debug_value

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions