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
I found #2466 (comment), which prevents HMR from breaking if there are circular dependencies, but I'm not sure what are the drawbacks
// vite.config.tsexportdefaultdefineConfig({plugins: [// your plugins,{name: "singleHMR",handleHotUpdate({ modules }){modules.map((m)=>{// m.importedModules = new Set(); // for vite 4m.clientImportedModules=newSet();// for vite 5m.importers=newSet();});returnmodules;},},],});
I recently did a code refactor and clean up on my project, including updating Vite from 4 to 5, and I decided to try to revisit this issue again, I thought "oh maybe Vite improved or fixed the cyclic imports issues", I tried removing that plugin after I updated to Vite 5 and my HMR started to break again. After some searching, I found #14975 (comment)
Which to me, it sounds like Vite will not / is not supposed to support circular imports, I tried to refactor my code so it doesn't have circular imports, but I decided that it's not worth it.
For now, I'm going back to the singleHMR plugin, which seems to still work fine, but I'm worried that it might bite me in the butt later.
How do you guys handle circular imports on your Vite project? Do you just try to avoid circular imports as much as possible? From what I see, this poor circular import experience is a bummer for some developers.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've been battling with Vite's HMR for 1.5 years now. My project has some circular dependencies that cause Vite's HMR to not work properly.
It all started with getting
HMR error: Cannot access '...' before initialization
error from late 2022, until I found #2466 (comment), which magically makes the HMR work again (I also commented on the issue, sharing the solution)I recently did a code refactor and clean up on my project, including updating Vite from 4 to 5, and I decided to try to revisit this issue again, I thought "oh maybe Vite improved or fixed the cyclic imports issues", I tried removing that plugin after I updated to Vite 5 and my HMR started to break again. After some searching, I found #14975 (comment)
Which to me, it sounds like Vite will not / is not supposed to support circular imports, I tried to refactor my code so it doesn't have circular imports, but I decided that it's not worth it.
For now, I'm going back to the
singleHMR
plugin, which seems to still work fine, but I'm worried that it might bite me in the butt later.How do you guys handle circular imports on your Vite project? Do you just try to avoid circular imports as much as possible? From what I see, this poor circular import experience is a bummer for some developers.
Beta Was this translation helpful? Give feedback.
All reactions