New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when dependency modules use React.lazy, vite convert more 'default' wrapped the component #4553
Comments
Because @material-ui/icons/Search is a comonJS module, vite will convert it to esm during dependency pre-bundling, so React.lazy(async () => (await import('@material-ui/icons/Search')).default) |
I'm still confused, when I use |
In other words,when I use a third part dependency, what's the applicable way to use React.lazy, ? React.lazy(async () => (await import('@material-ui/icons/Search')).default) |
Both ways are possible, only the time to load the module is different. The And the dynamic import
|
Thx for your detailed document link,but I still want to know if (await import('@material-ui/icons/Search')) returns the entire module object,why when I use |
However, if I dynamic import local files: const Child = React.lazy(() => import('./child')) it can work well, |
@ygj6 It looks like an edge case for lazyImport, which is handled properly in static import. I'm working on it. |
Good, I mistakenly thought the problem was caused by |
So,when will fix the bug?In next version?
…---Original---
From: ***@***.***>
Date: Sat, Aug 14, 2021 16:46 PM
To: ***@***.***>;
Cc: ***@***.***>;"State ***@***.***>;
Subject: Re: [vitejs/vite] when dependency modules use React.lazy, vite convert more 'default' wrapped the component (#4553)
Good, I mistakenly thought the problem was caused by esbuild conversion code and I stopped analyzing the problem, fortunately you found the correct cause.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
@SheldonWatson It should be the nearest version after #4596 merged. After reading commit history, I think it should be v2.5.0. |
Thx,By the way,did you notice in cjs package,requie static resource such as image will throw error,but require js is ok!
…---Original---
From: "Yunfei ***@***.***>
Date: Sat, Aug 14, 2021 18:11 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [vitejs/vite] when dependency modules use React.lazy, vite convert more 'default' wrapped the component (#4553)
@SheldonWatson It should be the nearest version after #4596 merged. After reading commit history, I think it should be v2.5.0.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
@SheldonWatson I haven't met such cases. It will be good to open another issue to track the problem and provide a reproduction example. |
|
Have you fixed it? I update vite to 2.5.0,but it still doesn't work! |
@SheldonWatson It's still pending and not merged #4596. |
Describe the bug
When I use this code:
throw this error:
I guess vite may convert more 'default' wrapped the component, which cause the error.
Reproduction
https://github.com/SheldonWatson/vite-commonjs-isure
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: