Skip to content

fix(dev): only override NODE_ENV override when initialising server#1161

Merged
danielroe merged 1 commit intonuxt:mainfrom
Mixerou:fix/move-node-env-override
Dec 17, 2025
Merged

fix(dev): only override NODE_ENV override when initialising server#1161
danielroe merged 1 commit intonuxt:mainfrom
Mixerou:fix/move-node-env-override

Conversation

@Mixerou
Copy link
Copy Markdown
Contributor

@Mixerou Mixerou commented Dec 15, 2025

❓ 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

Currently, all .ts files are loaded on nuxi startup. This entails dev/index.ts to set the initial NODE_ENV to development and as a result, other commands that do not override this value end up using it, ignoring user-defined NODE_ENV (from the system or .env file).

I moved this logic into the initialize function so this override happens only for the dev command.

🛝 Example

Consider a CI workflow where you are preparing for deployment:

  • Set NODE_ENV=production
  • Install only production dependencies (npm install --omit=dev, bun install --production, etc.)
  • Run nuxi prepare to generate types (or simply wait for postinstall script)

If your nuxt.config.ts contains logic meant only for development (which relies on dev dependencies, for example), checking process.env['NODE_ENV'] === 'development' inside the config will return true even though you explicitly set it to production.

✴️ Potential weakness

ipc is still initialized on nuxi startup no matter what command is executed later. However, I don't see any issues with this, even in situations where the user defines NODE_ENV=production or leaves it empty. All tests passed.

@Mixerou Mixerou requested a review from danielroe as a code owner December 15, 2025 12:48
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Dec 15, 2025

  • nuxt-cli-playground

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

commit: 02bd22a

@github-actions
Copy link
Copy Markdown
Contributor

📦 Bundle Size Comparison

📈 nuxi

Metric Base Head Diff
Rendered 4455.19 KB 4455.39 KB +0.21 KB (+0.00%)

📉 nuxt-cli

Metric Base Head Diff
Rendered 135.66 KB 135.65 KB -0.01 KB (-0.01%)

➡️ create-nuxt

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

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@95f4a0c). Learn more about missing BASE report.

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.
📢 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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 15, 2025

CodSpeed Performance Report

Merging #1161 will not alter performance

Comparing Mixerou:fix/move-node-env-override (02bd22a) with main (95f4a0c)

Summary

✅ 2 untouched

},
async run(ctx) {
// Prepare
overrideEnv('development')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This line does not affect other commands, but we call initialize on line 83, where we now override NODE_ENV.

@danielroe danielroe changed the title fix(nuxi): move NODE_ENV override to dev.initialize fix(dev): only override NODE_ENV override when initialising server Dec 17, 2025
@danielroe danielroe merged commit 4f5cf67 into nuxt:main Dec 17, 2025
12 checks passed
@github-actions github-actions bot mentioned this pull request Dec 17, 2025
@Mixerou Mixerou deleted the fix/move-node-env-override branch December 17, 2025 18:48
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.

3 participants