vite icon indicating copy to clipboard operation
vite copied to clipboard

[Bug]: Runtime imports with loadRemote are broken in safari

Open lucax88x opened this issue 5 months ago • 9 comments

Describe the bug

loadRemote does not work with Safari, in the repo example you can see that I have 3 LazyComponent (rendering the same remote/component) and two of them will always go in error due to:

Image Image

I suspect this is related to this safari bug

(it's not related to versions, I tried forking your example with vite 5, and had the same issue)

I'm well aware it could be a federation/runtime bug, and I'm also open to fix this bug, but I need some guidance there to understand where the issue could be. I was able to find out that the await import('component') in the virtual-exposes.mf it will give a "uninitialized" module in safari, but, why?

Version

7

Reproduction

https://github.com/lucax88x/module-federation-vite-react-bug

Relevant log output

ReferenceError: Cannot access uninitialized variable.

Validations

lucax88x avatar Jul 17 '25 08:07 lucax88x

Thanks for the report @lucax88x Unfortunately, I don't have Safari to reproduce this problem myself. 😢 I see that Safari bug has been around for ages 🤦

gioboa avatar Jul 17 '25 10:07 gioboa

I was a bit surprised that nobody with module-federation was bit by this problem and I was wondering If I was doing something wrong..

I'm open for a pairing session in case ;)

lucax88x avatar Jul 17 '25 11:07 lucax88x

if the problem is about imports like these:

// index.js
import('./mod.js').then(() => console.log('one'));
import('./mod.js').then(() => console.log('two'));

// mod.js
await new Promise(resolve => setTimeout(resolve, 1000));

we probably change the way we are importing modules 🤔

gioboa avatar Jul 17 '25 11:07 gioboa

Yikes, I don't have a mac either unless I use something like browserstack, but this might be something I will have to look at too since it could mean a decent number of mac users can't use my service.

pcfreak30 avatar Jul 27 '25 14:07 pcfreak30

There is an issue in Safari: https://bugs.webkit.org/show_bug.cgi?id=242740 You can workaround it with https://www.npmjs.com/package/vite-plugin-top-level-await

DemonStore avatar Aug 05 '25 14:08 DemonStore

I've already tried, unfortunately it doesn't fix the issue.

lucax88x avatar Aug 05 '25 15:08 lucax88x

Had the same trouble. https://www.npmjs.com/package/vite-plugin-top-level-await - helped

Ekaterina-T avatar Sep 18 '25 09:09 Ekaterina-T

vite-plugin-top-level-await resolved it for me as well.

bdrazen avatar Sep 18 '25 18:09 bdrazen

vite-plugin-top-level-await didn't work for me

rafaelcardeallodi avatar Oct 27 '25 19:10 rafaelcardeallodi