[PR #310] [MERGED] fix: CSS imports from node_modules crash SSR #467

Closed
opened 2026-05-06 13:08:14 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/310
Author: @Divkix
Created: 3/7/2026
Status: Merged
Merged: 3/7/2026
Merged by: @james-elicx

Base: mainHead: fix/node-modules-css-ssr-crash


📝 Commits (5)

  • fa24376 fix: CSS imports from node_modules crash SSR (#270)
  • f04a5ff fix: externalize better-sqlite3 and fix test hermiticity
  • adfa82c fix: propagate user ssr.external into RSC and SSR environments
  • 5a42454 fix: address review comments on node-modules CSS SSR crash fix
  • d9dc009 fix: address bonk review comments

📊 Changes

12 files changed (+252 additions, -7 deletions)

View changed files

📝 packages/vinext/src/index.ts (+41 -3)
📝 pnpm-lock.yaml (+16 -0)
tests/fixtures/app-basic/__test_packages__/fake-css-lib/index.js (+2 -0)
tests/fixtures/app-basic/__test_packages__/fake-css-lib/package.json (+1 -0)
tests/fixtures/app-basic/__test_packages__/fake-css-lib/styles.css (+1 -0)
tests/fixtures/app-basic/__test_packages__/fake-css-module-lib/index.js (+3 -0)
tests/fixtures/app-basic/__test_packages__/fake-css-module-lib/package.json (+1 -0)
tests/fixtures/app-basic/__test_packages__/fake-css-module-lib/styles.module.css (+1 -0)
tests/fixtures/app-basic/app/nextjs-compat/node-modules-css/page.tsx (+12 -0)
📝 tests/fixtures/app-basic/package.json (+3 -1)
📝 tests/fixtures/ecosystem/better-auth/vite.config.ts (+4 -3)
tests/node-modules-css.test.ts (+167 -0)

📄 Description

Summary

Fixes #270.

  • Set noExternal: true on all server environments (Pages Router SSR, App Router RSC, App Router SSR) to force node_modules through Vite's transform pipeline instead of Node's native ESM loader
  • This matches Next.js behavior of bundling everything for SSR — not just CSS, but any non-JS asset import from node_modules
  • Explicitly listed external packages (react, satori, resvg, yoga-wasm-web) take precedence per Vite's rules
  • Skipped for Cloudflare/Nitro targets which already bundle everything

Test plan

  • New tests/node-modules-css.test.ts — App Router + Pages Router tests with fake packages importing .css and .module.css (2/2 passing)
  • Existing CSS tests (tests/nextjs-compat/app-css.test.ts) — no regression (4/4 passing)
  • Features test (tests/features.test.ts) — no regression (231/231 passing)
  • Typecheck — clean
  • Lint — 0 warnings, 0 errors

🔄 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/310 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 3/7/2026 **Status:** ✅ Merged **Merged:** 3/7/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/node-modules-css-ssr-crash` --- ### 📝 Commits (5) - [`fa24376`](https://github.com/cloudflare/vinext/commit/fa24376b8447d555a272a1c125f6a0558163e2f8) fix: CSS imports from node_modules crash SSR (#270) - [`f04a5ff`](https://github.com/cloudflare/vinext/commit/f04a5fff25716eaeb1b5411eef23b80499bc9861) fix: externalize better-sqlite3 and fix test hermiticity - [`adfa82c`](https://github.com/cloudflare/vinext/commit/adfa82c9619ee82aed1e8a5508e48171018fba22) fix: propagate user ssr.external into RSC and SSR environments - [`5a42454`](https://github.com/cloudflare/vinext/commit/5a42454d8e75a3ca86afad3060a426aa4446bdb4) fix: address review comments on node-modules CSS SSR crash fix - [`d9dc009`](https://github.com/cloudflare/vinext/commit/d9dc009a5d6d817c72f4fbe4b5b87a8a809ac098) fix: address bonk review comments ### 📊 Changes **12 files changed** (+252 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+41 -3) 📝 `pnpm-lock.yaml` (+16 -0) ➕ `tests/fixtures/app-basic/__test_packages__/fake-css-lib/index.js` (+2 -0) ➕ `tests/fixtures/app-basic/__test_packages__/fake-css-lib/package.json` (+1 -0) ➕ `tests/fixtures/app-basic/__test_packages__/fake-css-lib/styles.css` (+1 -0) ➕ `tests/fixtures/app-basic/__test_packages__/fake-css-module-lib/index.js` (+3 -0) ➕ `tests/fixtures/app-basic/__test_packages__/fake-css-module-lib/package.json` (+1 -0) ➕ `tests/fixtures/app-basic/__test_packages__/fake-css-module-lib/styles.module.css` (+1 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/node-modules-css/page.tsx` (+12 -0) 📝 `tests/fixtures/app-basic/package.json` (+3 -1) 📝 `tests/fixtures/ecosystem/better-auth/vite.config.ts` (+4 -3) ➕ `tests/node-modules-css.test.ts` (+167 -0) </details> ### 📄 Description ## Summary Fixes #270. - Set `noExternal: true` on all server environments (Pages Router SSR, App Router RSC, App Router SSR) to force node_modules through Vite's transform pipeline instead of Node's native ESM loader - This matches Next.js behavior of bundling everything for SSR — not just CSS, but any non-JS asset import from node_modules - Explicitly listed `external` packages (react, satori, resvg, yoga-wasm-web) take precedence per Vite's rules - Skipped for Cloudflare/Nitro targets which already bundle everything ## Test plan - [x] New `tests/node-modules-css.test.ts` — App Router + Pages Router tests with fake packages importing `.css` and `.module.css` (2/2 passing) - [x] Existing CSS tests (`tests/nextjs-compat/app-css.test.ts`) — no regression (4/4 passing) - [x] Features test (`tests/features.test.ts`) — no regression (231/231 passing) - [x] Typecheck — clean - [x] Lint — 0 warnings, 0 errors --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:14 +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#467
No description provided.