Skip to content

Dev server resolving file paths inconsistently causing duplicated imports after hot load #19135

@spillz

Description

@spillz

Describe the bug

When running the dev server on a project where:

  • index.html references main.js
  • main.js references ./file2.js
  • file2.js references ./main.js

The server seemingly has issues identifying which files have already been loaded after a hot reload resulting in duplicate files causing errors and other unexpected runtime behavior. Here's my source list after the reload in Chrome's inspect panel:

image

The issue goes away if all files are imported their absolute paths (e.g. '/main.js' rather than './main.js') as described here. It appears that Vite isn't using a canonical path to identify the unique set of files for the update.

Reproduction

vite-test.zip

Steps to reproduce

unpack the zip files

cd <unpacked-folder>
npm i
npm run dev

change a file, save and check the source file list in browser's inspect panel.

System Info

Vite v6.0.6, Node v20, on Chomebook w/ ARM64 Linux but also replicated issue on windows.

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: htmlp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions