fix(dev): only override NODE_ENV override when initialising server#1161
Merged
fix(dev): only override NODE_ENV override when initialising server#1161
NODE_ENV override when initialising server#1161Conversation
commit: |
Contributor
📦 Bundle Size Comparison📈 nuxi
📉 nuxt-cli
➡️ create-nuxt
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1161 +/- ##
=======================================
Coverage ? 24.15%
=======================================
Files ? 89
Lines ? 4770
Branches ? 253
=======================================
Hits ? 1152
Misses ? 3586
Partials ? 32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #1161 will not alter performanceComparing Summary
|
danielroe
reviewed
Dec 17, 2025
| }, | ||
| async run(ctx) { | ||
| // Prepare | ||
| overrideEnv('development') |
Member
There was a problem hiding this comment.
this only happens when running nuxt dev.
I'm not sure what you mean about how this might affect other commands. can you explain more?
Contributor
Author
There was a problem hiding this comment.
This line does not affect other commands, but we call initialize on line 83, where we now override NODE_ENV.
NODE_ENV override to dev.initializeNODE_ENV override when initialising server
Merged
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.
❓ Type of change
📚 Description
Currently, all
.tsfiles are loaded onnuxistartup. This entailsdev/index.tsto set the initialNODE_ENVtodevelopmentand as a result, other commands that do not override this value end up using it, ignoring user-definedNODE_ENV(from the system or.envfile).I moved this logic into the
initializefunction so this override happens only for thedevcommand.🛝 Example
Consider a CI workflow where you are preparing for deployment:
NODE_ENV=productionnpm install --omit=dev,bun install --production, etc.)nuxi prepareto generate types (or simply wait forpostinstallscript)If your
nuxt.config.tscontains logic meant only for development (which relies on dev dependencies, for example), checkingprocess.env['NODE_ENV'] === 'development'inside the config will return true even though you explicitly set it toproduction.✴️ Potential weakness
ipcis still initialized onnuxistartup no matter what command is executed later. However, I don't see any issues with this, even in situations where the user definesNODE_ENV=productionor leaves it empty. All tests passed.