[PR #296] [MERGED] fix: set consumer: 'client' on client environment to fix Nitro ERR_UNSUPPORTED_ESM_URL_SCHEME #454

Closed
opened 2026-05-06 12:39:52 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/296
Author: @ask-bonk[bot]
Created: 3/6/2026
Status: Merged
Merged: 3/7/2026
Merged by: @southpolesteve

Base: mainHead: opencode/issue260-20260306041426


📝 Commits (1)

  • 9d3dff8 fix: set consumer: 'client' on client environment to fix Nitro ERR_UNSUPPORTED_ESM_URL_SCHEME

📊 Changes

1 file changed (+8 additions, -0 deletions)

View changed files

📝 packages/vinext/src/index.ts (+8 -0)

📄 Description

Summary

Fixes #260

  • Explicitly sets consumer: "client" on the client environment config so Nitro's configEnvironment hook can identify it before Vite applies default values

Root Cause

When Nitro's configEnvironment hook runs for each Vite environment, it checks config.consumer === "client" to skip client environments. However, Vite only defaults consumer to "client" for the "client" environment during config resolution — which happens after all configEnvironment hooks. Without an explicit consumer: "client" in vinext's environment config, Nitro sees consumer as undefined and incorrectly treats the client environment as a server-side service.

This causes Nitro to create a FetchableDevEnvironment for the client environment and load virtual:vinext-app-browser-entry in a Node.js worker thread. The browser entry imports @vitejs/plugin-rsc/browser, which Vite's fetchModule externalizes (it's a bare specifier). Node.js then natively loads browser.js, which contains import * as clientReferences from "virtual:vite-rsc/client-references" — and Node's ESM loader throws ERR_UNSUPPORTED_ESM_URL_SCHEME because virtual: is not a supported protocol.

Verification

  • Reproduced the error before the fix: pnpm run dev in examples/app-router-nitro shows the error
  • After the fix: no error, Nitro correctly logs Configuring client environment instead of Auto-detected service "client"
  • All 2199 existing tests pass (52 test files)
  • Typecheck and lint pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/296 **Author:** [@ask-bonk[bot]](https://github.com/apps/ask-bonk) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/7/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `opencode/issue260-20260306041426` --- ### 📝 Commits (1) - [`9d3dff8`](https://github.com/cloudflare/vinext/commit/9d3dff864f9a3b9c7903e952b73a2f35d0f8a018) fix: set consumer: 'client' on client environment to fix Nitro ERR_UNSUPPORTED_ESM_URL_SCHEME ### 📊 Changes **1 file changed** (+8 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+8 -0) </details> ### 📄 Description ## Summary Fixes #260 - Explicitly sets `consumer: "client"` on the client environment config so Nitro's `configEnvironment` hook can identify it before Vite applies default values ## Root Cause When Nitro's `configEnvironment` hook runs for each Vite environment, it checks `config.consumer === "client"` to skip client environments. However, Vite only defaults `consumer` to `"client"` for the `"client"` environment during config **resolution** — which happens after all `configEnvironment` hooks. Without an explicit `consumer: "client"` in vinext's environment config, Nitro sees `consumer` as `undefined` and incorrectly treats the client environment as a server-side service. This causes Nitro to create a `FetchableDevEnvironment` for the client environment and load `virtual:vinext-app-browser-entry` in a Node.js worker thread. The browser entry imports `@vitejs/plugin-rsc/browser`, which Vite's `fetchModule` externalizes (it's a bare specifier). Node.js then natively loads `browser.js`, which contains `import * as clientReferences from "virtual:vite-rsc/client-references"` — and Node's ESM loader throws `ERR_UNSUPPORTED_ESM_URL_SCHEME` because `virtual:` is not a supported protocol. ## Verification - Reproduced the error before the fix: `pnpm run dev` in `examples/app-router-nitro` shows the error - After the fix: no error, Nitro correctly logs `Configuring client environment` instead of `Auto-detected service "client"` - All 2199 existing tests pass (52 test files) - Typecheck and lint pass --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:52 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#454
No description provided.