How do you guys handle circular imports? #16424
Unanswered
SuspiciousLookingOwl
asked this question in
Q&A
Replies: 2 comments 2 replies
-
@SuspiciousLookingOwl any updates? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I was able to get out of some circular dependencies by using the global scope |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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