vite: require-externals facade loads lazily required externals at start-up (cosmiconfig -> typescript throws __filename), regression from #4889
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 43/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript, vite
- Ambito
- backend, build-system
Direzione di ricerca
Start by tracing the nitro:require-externals facade and how it handles the lazy require() described in the issue, then inspect the generated _ssr/ssr.mjs and _libs/typescript.mjs output. Reproduce with a CommonJS dependency that requires typescript inside a function in a nitro/vite app. Done means the external is not evaluated at server startup when the lazy loader is unused, while the React external fix from #4889 still works.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- nitro
3.0.261103-rc(vianitro/vite), TanStack Start 1.168, Vite 8.2 (Rolldown), React 19.2 - Node 22.23.4, Windows, Bun 1.3 as package manager
- Preset: node server, built with
vite build
What happens
On 3.0.260903-beta we hit #4171: use-sync-external-store/shim (via Base UI) left a runtime __require("react") in the SSR bundle, which loaded a second React and every SSR render failed with a null dispatcher.
3.0.261103-rc fixes that (thanks for #4889): the built server has no __require("react") left.
But the same change now loads, at server start-up, an external that CommonJS code only requires lazily. In our case cosmiconfig requires typescript lazily, and only to read .ts config files:
- With the beta, the output kept it lazy (an
await import(...)inside the loader). - With the RC it becomes a top-level
var import_typescript = __toESM(require_typescript())in_ssr/ssr.mjs, through thenitro:require-externalsfacade.
The bundled _libs/typescript.mjs (7.8 MB) then throws on load:
ReferenceError: __filename is not defined in ES module scope
at _libs/typescript.mjs:7355
The server prints "Listening", but every request answers 500 {"error":true,"status":500,"unhandled":true}.
Expected
A require() that CommonJS makes lazily, inside a function, stays lazy, as it did in the beta. Or the facade is created lazily, so a dependency that is never used at run time is never evaluated.
Notes
- Nothing in our Nitro config is affected by the RC's breaking changes (we use
preset,features.websocket,plugins,traceDeps,compressPublicAssets,routeRules). The build itself runs clean, with no warnings. - For now we stay on the beta and redirect
use-sync-external-store/shimanduse-sync-external-store/shim/with-selectorto an ESM module over React's own hook in the SSR environment, as a workaround for #4171.
I don't have a minimal repro yet. The trigger should be any bundled CommonJS dependency that does function load() { return require("typescript") } (cosmiconfig does this) in an app built with nitro/vite.
- Lingua principale
- TypeScript
- Stelle
- 11.5k
- Fork
- 968
- Merge medio
- 4g 9h
- PR unite (30g)
- 64
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nitrojs/nitro
-
pending triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 2 giorni
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configForse già presa @draarivpatel-ui l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
I maintainer di solito rispondono entro 2 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
pending triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
nitrojs/nitro#5205 · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di nitrojs/nitro
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno