fix(nuxi): pass --dotenv argument to showVersions in build command#1189
Merged
fix(nuxi): pass --dotenv argument to showVersions in build command#1189
Conversation
commit: |
Contributor
📦 Bundle Size Comparison📈 nuxi
📈 nuxt-cli
➡️ create-nuxt
|
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Fixes: nuxt/nuxt#33806
❓ Type of change
📚 Description
When using
--dotenv .env.productionwithnuxt build, custom environment files were not being applied toruntimeConfigvalues.The Problem
showVersions()inbanner.tscallsloadNuxtConfig({ cwd })without the--dotenvoption to display the version banner before the build starts.This causes the config to be loaded with only the default
.envfile (or none), andprocess.env.NUXT_*variables from custom env files areundefinedat that point.When
loadNuxt()is called afterwards with the correct dotenv options, the config values are already resolved with the wrong (empty) values.Why
.tsworked but.jsdidn't.tsfiles: jiti transforms and evaluates withmoduleCache: false- no caching.jsESM files: jiti delegates to Node.js nativeimport()- Node.js caches the moduleWhen the first
loadNuxtConfig()call happens without dotenv,process.envis empty. For.jsfiles, Node.js caches the module with empty values. The subsequentloadNuxt()call with correct dotenv options gets the cached module - the newprocess.envvalues are ignored.The Fix
Pass
ctx.args.dotenvtoshowVersions()so the first config load already uses the correct environment file.banner.ts: Add optionaldotenvparameter toshowVersions()build.ts: Passctx.args.dotenvtoshowVersions()