Skip to content
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

warn if HMR failed due a circular dependency issue #7893

Closed
4 tasks done
yeion7 opened this issue Apr 25, 2022 · 5 comments · Fixed by #14867
Closed
4 tasks done

warn if HMR failed due a circular dependency issue #7893

yeion7 opened this issue Apr 25, 2022 · 5 comments · Fixed by #14867

Comments

@yeion7
Copy link

yeion7 commented Apr 25, 2022

Clear and concise description of the problem

Vite's HMR fails if in some point of the dependency tree find a circular dependency issue, and then as a fallback triggers a ful l page reload, but the user doesn't get some info to be able to fix the issue

Suggested solution

If the HMR fails due a circular dependency, display a message for users about it

updateModules uses a utils propagateUpdate to traverse the files dependency tree and if find a circular dependency, returns true to triggers a full page reload,

My proposal is, instead of return a boolean, updateModules could return ModuleNode | undefined, if returns a ModuleNode, triggers a page reload, and send a message with the module and the importers

Alternative

No response

Additional context

I have been migrating from create-react-app@5 to vite@2.9.5 and this was annoying, I could't realized why HMR works with some files but not with others, I had to use ndb, and put a debugger here, then edit a file and debug the issue, I realized that I have a lot of circular dependency issues in my project 🙈

Validations

@bluwy
Copy link
Member

bluwy commented Apr 25, 2022

Related #3033

@sapphi-red sapphi-red mentioned this issue Jul 3, 2022
7 tasks
@josephbuchma
Copy link

This would be awesome, I spent way too much time figuring out what's wrong after migrating from CRA.
Here are a few tips for those who find themselves in a similar situation (for TypeScript):

  1. Find all circular dependencies in your codebase using madge: npx madge --circular --extensions ts ./
  2. I found out that a lot of those circular imports in my project were imports of typescript type definitions, and it turns out that if you import them using import type instead of regular import, vite does not care if those are introducing circular dependency.

To quickly refactor all type imports with import type, add following rule to your eslintrc:

    "@typescript-eslint/consistent-type-imports": [
      "error",
      {
        "prefer": "type-imports",
        "disallowTypeAnnotations": false
      }
    ]

then run eslint with --fix flag to replace all type imports with import type ...

Also related #10208

@jessegavin
Copy link

jessegavin commented Nov 28, 2022

We recently migrated a large Vue app from Vue CLI (Webpack) to Vite. This issue has been the biggest pain point for us.

Tools like madge are very helpful in finding circular dependencies, but it doesn't work with Vue single file components out of the box. Even after implementing a solution to find circular dependencies with madge I am still encountering page reload updates instead of mot module updates.

This is a big deal to our team, please consider implementing this.

@artnikbrothers
Copy link

artnikbrothers commented Feb 10, 2023

I have the same issue with React app after migrating from CRA to Vite

@evanshe
Copy link

evanshe commented Apr 19, 2023

#2466 try this, may be help

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants