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
In SSR, files seem to be collapsed into a single output file. However, this causes an issue with top level await because while promises would normally allow the rest of the file to be parsed and all top level variables to be defined, the browser immediately evaluates the promise and cannot get the value of the variable.
For example, consider the following code (this is roughly what you would expect await import("simple.js") to compile into)
The browser logs undefined, instead of the expected value of "hi".
This is important because using imports and top level await is a way to only import modules when in the browser and not on the server (or vice versa). For example, with SolidJS, I'm doing const mymodule = isServer ? await import ("server-module") : await import("client-stub")
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/core instead.
Describe the bug
In SSR, files seem to be collapsed into a single output file. However, this causes an issue with top level await because while promises would normally allow the rest of the file to be parsed and all top level variables to be defined, the browser immediately evaluates the promise and cannot get the value of the variable.
For example, consider the following code (this is roughly what you would expect
await import("simple.js")
to compile into)The browser logs undefined, instead of the expected value of
"hi"
.This is important because using imports and top level await is a way to only import modules when in the browser and not on the server (or vice versa). For example, with SolidJS, I'm doing
const mymodule = isServer ? await import ("server-module") : await import("client-stub")
Reproduction
https://stackblitz.com/edit/node-zgcsub
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: