[Bug]: Runtime imports with loadRemote are broken in safari
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:
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
- [x] Read the docs.
- [x] Read the common issues list.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] The provided reproduction is a minimal reproducible example of the bug.
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 🤦
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 ;)
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 🤔
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.
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
I've already tried, unfortunately it doesn't fix the issue.
Had the same trouble. https://www.npmjs.com/package/vite-plugin-top-level-await - helped
vite-plugin-top-level-await resolved it for me as well.
vite-plugin-top-level-await didn't work for me