Skip to content

HMR crashes in Vite 6.2.2 #19690

Closed
Closed

Description

@Mikilll94

Describe the bug

There is a regression in Vite 6.2.2 related to Hot Module Replacement

In the repro if you run the dev server and make any update in App.tsx file you will get an error in the devtools

Image

Now your app and dev server is broken and you need to kill and restart it to make the app working again.

If you rollback to Vite 6.2.1, then HMR is working fine.

Reproduction

https://github.com/Mikilll94/vite-hmr-issue

Steps to reproduce

  1. Download repro project.
  2. Run npm install and then npm run dev
  3. Open devtools
  4. Do any change in App.tsx, i.e. change the content of h1 tag
  5. As you can see the app is broken and there is an error in devtools.

System Info

This command is not working for me on Windows but it does matter because I have provided a clear reproduction.

Used Package Manager

npm

Logs

No response

Validations

Activity

  1. added theissue type on Mar 20, 2025
  2. ArnaudBarre commented on Mar 20, 2025

    @ArnaudBarre
    Member

    Thanks for the repro. This is triggered by having circular references in your imports, and probably having the entrypoint be part of the cycle doesn't help. Probably this regression should be fixable, but my advice is too avoid circular imports, it makes HMR a lot more predictable.

  3. hi-ogawa commented on Mar 21, 2025

    @hi-ogawa
    Contributor

    I think this is related to #19601 which fixed other issue #19135. Cyclic imports (especially involving main entry /src/main.tsx) is fairly tricky and I would imagine that's already broken in some ways.

    Supporting this case might be out of scope and, like Arnaud said, we recommend to avoid exporting anything from main.tsx.

  4. hi-ogawa commented on Mar 24, 2025

    @hi-ogawa
    Contributor

    Now your app and dev server is broken and you need to kill and restart it to make the app working again.

    Hmm, I missed this one and it looks like this reproduces only with custom base. Without base, html script gets replaced with ?t=..., but with base, it's stripped off and that's causing two modules /app/src/main.tsx and /app/src/main.tsx?t=... to exist after reload.

    // without base
    <script type="module" src="/src/main.tsx?t=1742782690504"></script>
    
    // with base
    <script type="module" src="/app/src/main.tsx"></script>

    The working version without base https://stackblitz.com/edit/github-wn1mrcdz?file=vite.config.ts

  5. added
    p2-edge-case
    and removed on Mar 24, 2025
  6. locked and limited conversation to collaborators on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-case

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions