Skip to content

fix(runtime): avoid std-env in warning stub#4296

Open
onmax wants to merge 1 commit into
nitrojs:mainfrom
onmax:codex/fix-runtime-warn-std-env
Open

fix(runtime): avoid std-env in warning stub#4296
onmax wants to merge 1 commit into
nitrojs:mainfrom
onmax:codex/fix-runtime-warn-std-env

Conversation

@onmax
Copy link
Copy Markdown
Contributor

@onmax onmax commented May 30, 2026

🔗 Linked issue

No existing issue found. Minimal reproduction:

Link Expected
Bug nitro-v3-std-env-repro Fails with ERR_MODULE_NOT_FOUND for std-env
Fix nitro-v3-std-env-repro-fix Shows Nitro's warning and returns the stub config

Related history: #3629, #3861

PR made with Codex

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ 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

Nitro v3's published virtual runtime stubs are intended to let imports such as nitro/runtime-config work outside a built Nitro app. When that fallback is used outside tests, Nitro should show the warning added in #3861 and continue with the stub implementation.

The issue comes from the interaction between two earlier changes:

That creates a clean-install failure in Nitro v3 before the intended warning can run:

import { useRuntimeConfig } from "nitro/runtime-config";

console.log(useRuntimeConfig());

With only nitro@3.0.260522-beta installed, this currently throws:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'std-env' imported from .../nitro/dist/runtime/virtual/_runtime_warn.mjs

This PR keeps the install-footprint direction from #3629 by making the test guard dependency-free instead of adding std-env back to Nitro's production dependencies. The guard preserves the relevant std-env isTest behavior for this use case: suppress the warning when NODE_ENV === "test" or TEST is set.

The guard uses optional globalThis.process?.env, matching the environment access pattern already used by Nitro's runtime config and by std-env itself. The existing consola.warn behavior is left unchanged; this PR only removes the missing std-env runtime import.

I verified lint, build, and a local packed clean install without std-env; import("nitro/runtime-config") reaches Nitro's intended warning and returns the stub config.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@onmax is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f623bb50-10ef-4107-ba41-513fd05313e3

📥 Commits

Reviewing files that changed from the base of the PR and between 255b254 and a82bc56.

📒 Files selected for processing (1)
  • src/runtime/virtual/_runtime_warn.ts

📝 Walkthrough

Walkthrough

The pull request removes a dependency on the std-env module from the runtime warning file. Instead of importing isTest from std-env, the code now derives it locally by inspecting globalThis.process?.env for NODE_ENV === "test" or a truthy TEST value, keeping the warning condition unchanged.

Changes

Remove std-env dependency

Layer / File(s) Summary
Inline test environment detection
src/runtime/virtual/_runtime_warn.ts
The module replaces the std-env import with local isTest derivation from globalThis.process?.env (NODE_ENV === "test" or TEST truthy), preserving the runtime warning condition without external dependency.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(runtime): avoid std-env in warning stub' follows conventional commits format with a 'fix' type and descriptive scope/subject that accurately reflects the main change.
Description check ✅ Passed The description thoroughly explains the bug, root cause, solution, and verification steps, directly relating to the changeset's modifications to remove the std-env dependency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4296

commit: a82bc56

@onmax onmax force-pushed the codex/fix-runtime-warn-std-env branch 3 times, most recently from ce0a6a7 to 39e47f3 Compare May 30, 2026 15:17
@onmax onmax force-pushed the codex/fix-runtime-warn-std-env branch from 39e47f3 to a82bc56 Compare May 30, 2026 15:22
@onmax onmax marked this pull request as ready for review May 30, 2026 15:30
@onmax onmax requested a review from pi0 as a code owner May 30, 2026 15:30
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.

1 participant