cli icon indicating copy to clipboard operation
cli copied to clipboard

`nuxi preview` does not load dotenv before resolving output path

Open diaslucas1 opened this issue 8 months ago • 0 comments

Hello,

I have a custom Nitro output directory set via an environment variable (VITE_OUTPUT_PATH) defined in an .env file located outside the project root (e.g., my-env/.env).

When running:

nuxi build --dotenv=my-env/.env
nuxi preview --dotenv=my-env/.env

The build correctly respects the custom output directory, but the preview command ignores the dotenv file and tries to use the default output directory (.output/default), which causes it to fail.

Steps to reproduce

Open this project: https://stackblitz.com/edit/nuxt-starter-ixrmd6lk?file=my-env%2F.env Run the build and preview commands with the --dotenv option pointing to the custom .env file, and see that preview does not use the correct output path.

build --dotenv=my-env/.env preview --dotenv=my-env/.env
Image Image

Expected Behavior

The preview command should load the .env file before loading the Nuxt config, just like the build command does, so that it reads the correct environment variables and uses the right Nitro output directory.

Possible Solution

Looking at the preview command file, the loadNuxt call isn’t receiving the dotenv option like it does in the build command. Adding that option there to load the dotenv file early should fix the problem so nuxi preview picks up the right env vars and uses the correct Nitro output path.

diaslucas1 avatar Jun 17 '25 18:06 diaslucas1