Skip to content

Bug: Module ignores custom .env file specified via --dotenv flag #428

@thomas-auffroy

Description

@thomas-auffroy

Description

The module always writes new NUXT_SESSION_PASSWORD variables to the default .env file, even when a custom environment file is specified using the --dotenv flag (e.g., pnpm dev --dotenv .env.local).

Steps to Reproduce

  1. Create a custom environment file (e.g., .env.local)
  2. Run the development server with: pnpm dev --dotenv .env.local
  3. Observe that NUXT_SESSION_PASSWORD is written to .env instead of .env.local

Expected Behavior

When using --dotenv .env.local, the module should write environment variables to the specified file (.env.local) rather than the default .env file.

Actual Behavior

The module always writes to .env regardless of the --dotenv flag, because the file path is hardcoded in the module.

Root Cause

In module.ts, the environment file path is hardcoded:

// Current hardcoded implementation
const envPath = join(nuxt.options.rootDir, '.env');

Proposed Solution

Replace the hardcoded path with logic that respects the --dotenv command-line argument:

const dotEnvIndex = process.argv.findIndex(arg => arg === '--dotenv')
const envPath = join(nuxt.options.rootDir, dotEnvIndex !== -1 ? process.argv[dotEnvIndex + 1] : '.env');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions