Bug: client-mode build crashes (`ERR_MODULE_NOT_FOUND`) when adding nitro v3's vite plugin — prerender hook hardcodes `dist/server/server.js`
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- typescript, vite
- Domaine
- build-system, devtools
Piste de recherche
Reproduce the failure with the linked solid-2-nitro-repro at commit e31c0fa by running pnpm build, then inspect the client-mode solid:start/prerender hook and configurePreviewServer behavior described in dist/esm/index.mjs. Compare the Vite environment outputs with the hardcoded dist/server/server.js and dist/client/index.html paths. Done means the Nitro configuration builds without ERR_MODULE_NOT_FOUND and the integration has a clear ownership or path-handling behavior.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
Adding nitro v3 (nitro/vite) next to a client-mode start: true setup breaks the production build. The plugin's solid:start/prerender buildApp hook imports the SSR handler from a hardcoded dist/server/server.js, but nitro's vite plugin reroutes both environment outputs before that, so the file never exists and the build dies with a bare ERR_MODULE_NOT_FOUND pointing into the plugin's own dist/esm/index.mjs.
The same config with ssr: true (SSR mode) builds fine — nitro runs its own [SSR] → [Nitro] stages and produces .output/server/index.mjs (node-server preset). The crash is specific to client mode (ssr: false), where the prerender hook unconditionally reads dist/server.
Note that ssr: false + serverFunctions: true is a documented, legitimate server-bearing setup — not user error: the README's client-mode section says no server bundle remains "unless serverFunctions is enabled, in which case dist/server is kept and its handleRequest serves the endpoint". With server functions enabled there is server code by design even when SSR is off, and the README lists Nitro among the hosts that consume that { fetch }/handleRequest shape. So "Solid builds the server bundle, nitro hosts it" is the intended integration; only the client-mode build-time glue breaks it.
Reproduction
Two-commit repro repo: https://github.com/lkwr/solid-2-nitro-repro
| Commit | Config | pnpm build |
|---|---|---|
9fb2261 — "init bare solid 2.0 template" |
solid({ start: true, diagnostics: true }) |
✅ works |
e31c0fa — "add nitro & enable server functions" |
solid({ start: true, diagnostics: true, ssr: false, serverFunctions: true }) + nitro() |
❌ crashes |
git clone https://github.com/lkwr/solid-2-nitro-repro
pnpm install
git checkout e31c0fa
pnpm build
The only changes in commit 2 are vite.config.ts and package.json:
import { defineConfig } from 'vite';
import solid from '@solidjs/vite-plugin';
+import { nitro } from 'nitro/vite';
plugins: [
- solid({ start: true, diagnostics: true }),
+ solid({ start: true, diagnostics: true, ssr: false, serverFunctions: true }),
+ nitro()
],
+ "nitro": "^3.0.260903-beta",
Observed
vite v8.3.1 building client environment for production...
✓ 43 modules transformed.
.output/public/.vite/manifest.json 0.45 kB
.output/public/assets/logo-BKhbptE1.svg 1.59 kB
.output/public/assets/virtual_solid-ssr-entry-client-2z-wuqR5.js 39.63 kB
✓ built in 65ms
vite v8.3.1 building ssr environment for production...
✓ 8 modules transformed.
node_modules/.nitro/vite/services/ssr/server.js 6.62 kB
✓ built in 1.01s
error during build:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/Lukas/test/solid-nitro/dist/server/server.js' imported from /Users/Lukas/test/solid-nitro/node_modules/.pnpm/@[email protected][email protected]/node_modules/@solidjs/vite-plugin/dist/esm/index.mjs
at finalizeResolution (node:internal/modules/esm/resolve:241:11)
...
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///Users/Lukas/test/solid-nitro/dist/server/server.js'
Notes from bisecting the repro:
- Removing
serverFunctions: true(keepingstart: true,ssr: false+nitro()) still crashes identically — the prerender hook's import is unconditional in client mode. - Setting
ssr: truemakes the build succeed (nitro consumes the server side,.output/server/index.mjs). Only client mode crashes.
Root cause
In @solidjs/vite-plugin 3.0.0-next.46, dist/esm/index.mjs, the client-mode prerender hook (solid:start/prerender, order: 'post'):
const serverDir = path.resolve(root, "dist/server"); // hardcoded
const handler = await import(
pathToFileURL(path.join(serverDir, "server.js")).href
);
const response = await handler.handleRequest(
new Request(new URL(base || "/", "http://localhost")),
);
writeFileSync(
path.resolve(root, "dist/client/index.html"),
await response.text(),
); // hardcoded
nitro's vite plugin patches the environments first: the client build lands in .output/public/…, the ssr environment in node_modules/.nitro/vite/services/ssr/server.js, and nitro then builds its own .output/server/…. Nothing ever writes dist/server/server.js, so the prerender import fails.
Affected assumptions in that hook (and the same hardcode family elsewhere — e.g. configurePreviewServer also does import(path.resolve(root, 'dist/server/server.js'))):
- The SSR handler is at
dist/server/server.js— but nitro (as a supported{ fetch }consumer per the README) reroutes environment outputs. - The prerendered shell is written to
dist/client/index.html— nitro's layout is.output/public. - In client mode
start.externalis documented as inert ("Server-only options are inert here … and so isstart.external"), so there is currently no supported seam to point the prerender/preview steps at a relocated server bundle.
What's missing is the build-time seam: the plugin's dev middlewares stand down automatically when a host adopts the ssr environment, but the client-mode prerender (and preview dispatch) still read the hardcoded path.
Expected behavior
One (or more) of:
- Derive the SSR handler location from the resolved environment (the outDir/entry the ssr environment was actually built to) rather than a hardcoded
dist/server. - When another plugin has taken ownership of / rerouted the ssr environment (as nitro v3 does — the same ownership the plugin already detects in dev to stand its middlewares down), skip the plugin's own prerender/preview dispatch (nitro can prerender itself) instead of importing a path that no longer matches.
- At minimum, surface a clear diagnostic ("SSR handler not found at
<root>/dist/server/server.js— if another plugin owns the server build, configure X") instead of a bareERR_MODULE_NOT_FOUNDwhose only importer reference points into@solidjs/vite-plugin/dist/esm/index.mjs.
Environment
@solidjs/vite-plugin |
3.0.0-next.46 |
solid-js / @solidjs/web / @solidjs/diagnostics |
2.0.0-rc.11 |
vite |
8.3.1 |
nitro |
3.0.260903-beta (nitro/vite) |
| node / pnpm | v26.10.0 / 12.6.0 |
| OS | macOS |
- Langage dominant
- TypeScript
- Étoiles
- 522
- Forks
- 72
- Merge moyen
- 1 j 6 h
- PR mergées (30 j)
- 33
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de solidjs/solid-vite-plugin
-
Test environment detection doesn't consider Vitest workspacesPeut-être pris @carloitaben l’a pris il y a 52 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
solidjs/solid-vite-plugin#205 · 1 commentaire · 2 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
solidjs/solid-vite-plugin#411 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
solidjs/solid-vite-plugin#369 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
solidjs/solid-vite-plugin#328 ·
Les mainteneurs répondent en général sous 1 jour
-
Retain $ServerOnly templates while HMR is activePeut-être pris @brenelz l’a pris il y a 26 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
solidjs/solid-vite-plugin#308 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de solidjs/solid-vite-plugin
Issues similaires
-
e2e-failure ready-to-code
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
redhat-developer/rhdh-plugin-export-overlays#4391 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
Luligu/matterbridge#655 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
software-mansion/argent#1457 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
schmayterling/hibi#245 ·
Les mainteneurs répondent en général sous 1 jour
-
After a failed save, the red error banner stays on every page until the app is reloadedPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverteai-driven-qa bug claude Minor
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
linagora/twake-contacts-frontend#241 ·
Les mainteneurs répondent en général sous 1 jour