You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Server running on http://localhost:3000
4:43:15 PM [vite] (ssr) Error when evaluating SSR module ./root-server.tsx: module is not defined
at eval (/<repo>/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js:8:3)
at ESModulesEvaluator.runInlinedModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1057:6)
at SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1271:82)
at SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30895:35)
at SSRCompatModuleRunner.cachedRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1166:28)
at request (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1215:79)
at async eval (/<repo>/root-server.tsx:3:44)
at async ESModulesEvaluator.runInlinedModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1049:5)
at async SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1271:61)
at async SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30895:23)
at async SSRCompatModuleRunner.cachedRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1167:76)
at async SSRCompatModuleRunner.import (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1104:12)
at async instantiateModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30852:12)
at async file:///<repo>/server.mjs:55:26
I roughly debugged into vite source code and found the fetchModule() didn't handle the alias very well when deciding whether it's an external resource in SSR mode:
[fetchModule] { url: './root-server.tsx', importer: undefined }
[fetchModule] {
url: '/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js',
importer: '/<repo>/root-server.tsx'
}
5:35:19 PM [vite] (ssr) Error when evaluating SSR module ./root-server.tsx: module is not defined
at eval (/<repo>/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js:8:3)
at ESModulesEvaluator.runInlinedModule (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:3911:11)
at SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4200:26)
at SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4524:36)
at SSRCompatModuleRunner.cachedRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4054:28)
at request (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4124:19)
at async eval (/<repo>/root-server.tsx:3:44)
at async ESModulesEvaluator.runInlinedModule (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:3911:5)
at async SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4200:5)
at async SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4524:24)
at async SSRCompatModuleRunner.cachedRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4057:33)
at async SSRCompatModuleRunner.import (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:3972:12)
at async instantiateModule (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4481:12)
at async file:///<repo>/server.mjs:55:26
Server running on http://localhost:3000
4:43:15 PM [vite] (ssr) Error when evaluating SSR module ./root-server.tsx: module is not defined
at eval (/<repo>/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js:8:3)
at ESModulesEvaluator.runInlinedModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1057:6)
at SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1271:82)
at SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30895:35)
at SSRCompatModuleRunner.cachedRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1166:28)
at request (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1215:79)
at async eval (/<repo>/root-server.tsx:3:44)
at async ESModulesEvaluator.runInlinedModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1049:5)
at async SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1271:61)
at async SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30895:23)
at async SSRCompatModuleRunner.cachedRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1167:76)
at async SSRCompatModuleRunner.import (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1104:12)
at async instantiateModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30852:12)
at async file:///<repo>/server.mjs:55:26
Server running on http://localhost:3000
4:43:15 PM [vite] (ssr) Error when evaluating SSR module ./root-server.tsx: module is not defined
at eval (/<repo>/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js:8:3)
at ESModulesEvaluator.runInlinedModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1057:6)
at SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1271:82)
at SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30895:35)
at SSRCompatModuleRunner.cachedRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1166:28)
at request (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1215:79)
at async eval (/<repo>/root-server.tsx:3:44)
at async ESModulesEvaluator.runInlinedModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1049:5)
at async SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1271:61)
at async SSRCompatModuleRunner.directRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30895:23)
at async SSRCompatModuleRunner.cachedRequest (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1167:76)
at async SSRCompatModuleRunner.import (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/module-runner.js:1104:12)
at async instantiateModule (file:///<repo>/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:30852:12)
at async file:///<repo>/server.mjs:55:26
[fetchModule] { url: './root-server.tsx', importer: undefined }
[fetchModule] {
url: '/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js',
importer: '/<repo>/root-server.tsx'
}
5:35:19 PM [vite] (ssr) Error when evaluating SSR module ./root-server.tsx: module is not defined
at eval (/<repo>/node_modules/.pnpm/[email protected]/node_modules/react/jsx-dev-runtime.js:8:3)
at ESModulesEvaluator.runInlinedModule (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:3911:11)
at SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4200:26)
at SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4524:36)
at SSRCompatModuleRunner.cachedRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4054:28)
at request (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4124:19)
at async eval (/<repo>/root-server.tsx:3:44)
at async ESModulesEvaluator.runInlinedModule (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:3911:5)
at async SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4200:5)
at async SSRCompatModuleRunner.directRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4524:24)
at async SSRCompatModuleRunner.cachedRequest (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4057:33)
at async SSRCompatModuleRunner.import (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:3972:12)
at async instantiateModule (file:///<vite>/dist/node/_chunk-4PQHSIBL.js:4481:12)
at async file:///<repo>/server.mjs:55:26
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
For now, this is how alias is designed to work and the behavior is same between Vite 5 and Vite 6. Without alias, import "react" is not transformed by vite's import analysis and later fetchModule resolves as external for module runner execution. With alias, import "react" is replaced with alias during import analysis and fetchModule treat it as "non external".
Describe the bug
When setting a package alias (for example
react
) to its root dir like:in SSR mode, it will cause an error like:
I roughly debugged into vite source code and found the
fetchModule()
didn't handle the alias very well when deciding whether it's an external resource in SSR mode:without react alias:
with react alias:
Reproduction
https://github.com/Jinjiang/reproductions/tree/try-vite-ssr-20250213
Steps to reproduce
How to reproduce:
Open
server.mjs
and add below intoresolve.alias
config:Then:
Open
http://localhost:3000
in browser.error log:
System Info
Used Package Manager
pnpm
Logs
error log:
fetchModule without react alias:
fetchModule with react alias:
Validations
The text was updated successfully, but these errors were encountered: