Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nuxt preview does not respect the --dotenv option #383

Closed
martinszeltins opened this issue Mar 30, 2024 · 9 comments
Closed

nuxt preview does not respect the --dotenv option #383

martinszeltins opened this issue Mar 30, 2024 · 9 comments
Labels

Comments

@martinszeltins
Copy link

Environment

Stackblitz

------------------------------
- Operating System: Linux
- Node Version:     v18.18.0
- Nuxt Version:     3.11.1
- CLI Version:      3.11.1
- Nitro Version:    2.9.5
- Package Manager:  [email protected]
- Builder:          -
- User Config:      devtools, runtimeConfig
- Runtime Modules:  -
- Build Modules:    -
------------------------------

Reproduction

https://stackblitz.com/edit/nuxt-starter-qwahbu?file=package.json

Describe the bug

I have 2 environment files .env and .env.prod. According to the docs, I can pass the --dotenv flag to specify a different env file to load for nuxt preview command - https://nuxt.com/docs/api/commands/preview

But it does not seem to work.

I have tried multiple variants of this and it always loads the .env file and not my .env.prod file.

Here is what I tried (see reproduction):

+ "preview": "nuxt preview --dotenv .env.prod"
+ "preview": "nuxt preview --dotenv=.env.prod"
+ "preview": "nuxt preview --dotenv prod"

Nothing worked.

Additional context

No response

Logs

No response

Copy link

stackblitz bot commented Mar 30, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@manniL manniL transferred this issue from nuxt/nuxt Mar 30, 2024
@chrisspiegl
Copy link

I have just experienced the same (with Nuxt 3.10.3 as well as 3.11.2).

Doc says it should work (https://nuxt.com/docs/api/commands/preview)

But my terminal even says it's just going to load .env

Xnapper-2024-04-23-18 34 45

I hope this helps possibly locate the issue.

@dixhuit
Copy link

dixhuit commented Oct 2, 2024

Been going mad experiencing the exact same issue. Nuxt 3.13.2.

@igoohd
Copy link

igoohd commented Oct 11, 2024

Same problem here, any updates?

@manniL manniL added bug Something isn't working preview labels Oct 11, 2024
@manniL
Copy link
Member

manniL commented Oct 11, 2024

As a workaround, read in the .env variables as you'd have to on the server 👍🏻

@dixhuit
Copy link

dixhuit commented Oct 22, 2024

3fe1ff9 only appears to fix the console message, which is great, but doesn't address the reported issue (nuxt preview does not respect the --dotenv option ). Can we re-open this?

@danielroe
Copy link
Member

danielroe commented Oct 22, 2024

Would you provide a reproduction of it not working? It works fine for me - including in the originally provided stackblitz:

@dixhuit
Copy link

dixhuit commented Oct 22, 2024

Ah, the original stackblitz repro is also working for me (first time trying it I'll admit). Hmm, need to double check my local project now...

@dixhuit
Copy link

dixhuit commented Oct 23, 2024

Yep, not sure where the confusion stems from but my local project is behaving as expected now. Apologies for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants