Skip to content

fix(nuxi): pass --dotenv argument to showVersions in build command#1189

Merged
danielroe merged 1 commit intonuxt:mainfrom
Flo0806:fix/pass-dotenv-to-show-versions
Jan 16, 2026
Merged

fix(nuxi): pass --dotenv argument to showVersions in build command#1189
danielroe merged 1 commit intonuxt:mainfrom
Flo0806:fix/pass-dotenv-to-show-versions

Conversation

@Flo0806
Copy link
Copy Markdown
Member

@Flo0806 Flo0806 commented Jan 16, 2026

🔗 Linked issue

Fixes: nuxt/nuxt#33806

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

When using --dotenv .env.production with nuxt build, custom environment files were not being applied to runtimeConfig values.

The Problem

showVersions() in banner.ts calls loadNuxtConfig({ cwd }) without the --dotenv option to display the version banner before the build starts.

This causes the config to be loaded with only the default .env file (or none), and process.env.NUXT_* variables from custom env files are undefined at that point.

When loadNuxt() is called afterwards with the correct dotenv options, the config values are already resolved with the wrong (empty) values.

Why .ts worked but .js didn't

  • .ts files: jiti transforms and evaluates with moduleCache: false - no caching
  • .js ESM files: jiti delegates to Node.js native import() - Node.js caches the module

When the first loadNuxtConfig() call happens without dotenv, process.env is empty. For .js files, Node.js caches the module with empty values. The subsequent loadNuxt() call with correct dotenv options gets the cached module - the new process.env values are ignored.

The Fix

Pass ctx.args.dotenv to showVersions() so the first config load already uses the correct environment file.

  • banner.ts: Add optional dotenv parameter to showVersions()
  • build.ts: Pass ctx.args.dotenv to showVersions()

@Flo0806 Flo0806 requested a review from danielroe as a code owner January 16, 2026 16:23
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 16, 2026

  • nuxt-cli-playground

    npm i https://pkg.pr.new/create-nuxt@1189
    
    npm i https://pkg.pr.new/nuxi@1189
    
    npm i https://pkg.pr.new/@nuxt/cli@1189
    

commit: f6abdd8

@github-actions
Copy link
Copy Markdown
Contributor

📦 Bundle Size Comparison

📈 nuxi

Metric Base Head Diff
Rendered 4439.74 KB 4439.83 KB +0.09 KB (+0.00%)

📈 nuxt-cli

Metric Base Head Diff
Rendered 137.28 KB 137.37 KB +0.09 KB (+0.06%)

➡️ create-nuxt

Metric Base Head Diff
Rendered 2369.18 KB 2369.18 KB 0.00 KB (0.00%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 16, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing Flo0806:fix/pass-dotenv-to-show-versions (f6abdd8) with main (51bd75b)

Open in CodSpeed

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@51bd75b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
packages/nuxi/src/utils/banner.ts 0.00% 5 Missing ⚠️
packages/nuxi/src/commands/build.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1189   +/-   ##
=======================================
  Coverage        ?   24.50%           
=======================================
  Files           ?       89           
  Lines           ?     4844           
  Branches        ?      261           
=======================================
  Hits            ?     1187           
  Misses          ?     3627           
  Partials        ?       30           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! ❤️

@danielroe danielroe merged commit 362ab3a into nuxt:main Jan 16, 2026
12 checks passed
@github-actions github-actions bot mentioned this pull request Jan 16, 2026
@github-actions github-actions bot mentioned this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How do I make a custom env file work?

3 participants