Closed Antony92 closed 1 week ago
Start a new pull request in StackBlitz Codeflow.
From your system info, I think you're hitting a chrome bug:
I reproduced it in a fresh Vite (Vanilla) project. await import
in dev mode works ok, build & preview is blank on v129.0.6668.59 Chromium-based browsers.
I also tested await import
with React+Typescript+SWC (fresh project again) and it's the opposite. Dev mode shows empty screen and when built and previewed, it's working ok.
Can confirm, a relatively simple app created with @vitejs/plugin-react-swc is now behaving this way, producing a blank page, in Chrome/Edge 129. Running the same app in Opera 113 works fine.
There's no use of await import
in user code in this project, so I'm guessing some internal Vite use (or @vitejs/plugin-react-swc) is what's manifesting the issue.
Anything that can be done other than using another browser and waiting for an update to Chrome/Edge?
Can confirm, a relatively simple app created with @vitejs/plugin-react-swc is now behaving this way, producing a blank page, in Chrome/Edge 129. Running the same app in Opera 113 works fine.
There's no use of
await import
in user code in this project, so I'm guessing some internal Vite use (or @vitejs/plugin-react-swc) is what's manifesting the issue.Anything that can be done other than using another browser and waiting for an update to Chrome/Edge?
try vite-plugin-top-level-await
?
This seems to be related to a Chromium bug.
It's fixed in Chrome 130 available via the Canary nightly build or Microsoft Edge Canary and Dev Channel Builds.
I am using vite-plugin-top-level-await plugin as a temporary workaround.
~@SkyWalker653 This has done the trick for us, thanks for sharing, much appreciated!~ ~Spoke to soon, it did not work...~
It eventually did work but we loaded the plugin to late and in the wrong place. We are using Quasar with boot files and we had to add it to the vitePlugins in the quasar config to make this work.
Problem seems to be gone for me in Edge 130.
Closing as this seems to be fixed in chromium 130 and chrome/edge 130 has been released.
Describe the bug
For some reason when building for production and using top level await for an import() function that imports a module which imports another module the import() never completes with await. This started happening recently on Chrome (on Safari and Firefox it works fine) and this does not happen when running in dev mode. Not really sure if the issue is Chrome related or with vite bundle when running for production.
Here is a quick summary of the reproduce link:
We have a
main.ts
file with a top level await import formodule1.ts
module1.ts
includes an export of function that imports another module. In this casemodule2.ts
Now running this with stackblitz in dev mode
npm run dev
you should see "Finished" displayed on both Chrome and Safari. Runningnpm build-prod
and thennpm run preview
displays "Finished" in Safari, but in Chromeawait import('./module1')
never completes and you should see "Loading..."Workaround is to use
import('./module1').then(() => // code to be executed after module load)
instead ofawait import('./module1');
Reproduction
https://stackblitz.com/edit/vitejs-vite-85uvzu?file=src%2Fmain.ts
Steps to reproduce
npm run build-prod npm run preview
System Info
Used Package Manager
npm
Logs
No response
Validations