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
When any code meets all of the following criteria:
Is loaded using ssrLoadModule
Has a default named export
Has a reference to the above name in the same file
ssrLoadModule will incorrectly treat it as an anonymous function, preventing the rest of the code from accessing it.
This code style is used in various dependencies such as d3-format in order to modify function prototypes.
For example:
exportdefaultfunctionhello(){return1234;}console.log(typeofhello);// returns undefinedhello.test=1234;// [vite] Error when evaluating SSR module// ReferenceError: hello is not defined
As a sanity check, I have confirmed that:
The above code executes as expected when directly run from node
The default export is properly named when splitting the export from the function definition:
functionhello(){/* ... */}exportdefaulthello;console.log(typeofhello);// returns function
Named exports are not affected
exportfunctionhello(){/* ... */}console.log(typeofhello);// returns function
This is because of the ssrTransform step doesn't look for references to the default export, it only replaces export default with __vite_ssr_exports__.default =:
> vite-ssr-default@1.0.0 dev /home/runner/work/vite-ssr-default/vite-ssr-default
> node server
The variable "app" is of type undefined
9:46:16 AM [vite] Error when evaluating SSR module /src/app.js:
ReferenceError: app is not defined
at /src/app.js:6:1
at instantiateModule (/home/runner/work/vite-ssr-default/vite-ssr-default/node_modules/.pnpm/vite@2.4.0-beta.2/node_modules/vite/dist/node/chunks/dep-06e8fbb4.js:72663:166)
ReferenceError: app is not defined
at /src/app.js:6:1
at instantiateModule (/home/runner/work/vite-ssr-default/vite-ssr-default/node_modules/.pnpm/vite@2.4.0-beta.2/node_modules/vite/dist/node/chunks/dep-06e8fbb4.js:72663:166)
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 https://github.com/vuejs/vue-next instead.
Describe the bug
When any code meets all of the following criteria:
ssrLoadModule
ssrLoadModule
will incorrectly treat it as an anonymous function, preventing the rest of the code from accessing it.This code style is used in various dependencies such as d3-format in order to modify function prototypes.
For example:
As a sanity check, I have confirmed that:
This is because of the ssrTransform step doesn't look for references to the default export, it only replaces
export default
with__vite_ssr_exports__.default =
:vite/packages/vite/src/node/ssr/ssrTransform.ts
Lines 125 to 132 in e092e89
Producing the following transformed code:
Which now makes
hello
out of scope.Reproduction
https://github.com/GrygrFlzr/vite-ssr-default
You can see the logs from CI runs:
System Info
Used Package Manager
pnpm
Logs
Validations
The text was updated successfully, but these errors were encountered: