mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #585] SSR dev server fails with "module is not defined" for CJS dependencies (void-elements, highlight.js, etc.) #127
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#127
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ThyeeZz on GitHub (Mar 19, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/585
Description
When migrating a Next.js Pages Router project to vinext,
vinext devfails with500 Internal Server Errorbecause Vite 8'sESModulesEvaluatorcannot handle CommonJS dependencies that usemodule.exports.Reproduction
react-i18next→html-parse-stringify→void-elements, orhighlight.js)npx vinext initthennpx vinext devhttp://localhost:3000/Error
Error when evaluating SSR module /src/pages/index.tsx: module is not defined
at eval (node_modules/void-elements/index.js:8:1)
at ESModulesEvaluator.runInlinedModule (vite/dist/node/module-runner.js:988:161)
ReferenceError: module is not defined
at node_modules/void-elements/index.js:6:1
After externaling
void-elements, the same error occurs forhighlight.js/lib/core.js, and so on for other CJS-only packages.Attempted workarounds
ssr.noExternal: ['void-elements', ...]ssr.noExternal: truessr.external: ['void-elements', ...]ssr.external: truereactitself gets externalized and failsssr.external: [/node_modules/]Value is non of these types True, Array<T>Root cause
Vite 8's
ESModulesEvaluator(used bySSRCompatModuleRunner) runs module code in strict ESM scope wheremoduleis not defined. CJS packages that usemodule.exports = ...fail immediately. Vite's CJS→ESM transform doesn't seem to kick infor these dependencies during SSR dev.
Environment
Affected packages (partial list)
void-elements(viareact-i18next→html-parse-stringify)highlight.jsreactitself (react/index.jsusesmodule.exports)Expected behavior
vinext should handle CJS dependencies transparently in SSR dev mode, similar to how Next.js webpack does.