Skip to content

import.meta.glob negative pattern hmr failure #20852

@MoritzLoewenstein

Description

@MoritzLoewenstein

Describe the bug

import.meta.glob does not hmr correctly when the glob pattern is an array with exclusions, e.g.

import.meta.glob(["./modules/*.js", "!./modules/_a.js"], {
  import: "default",
  eager: true,
});

The same behaviour can be observed when using rolldown-vite (not sure if a separate issue is necessary?)

Reproduction

https://github.com/MoritzLoewenstein/vite-import-glob-repro

Steps to reproduce

Issue 1: Adding a file which matches the glob import

  1. npm run dev
  2. npm run addMod
  3. page does not change

Expected Result: The following should be visible on the page

./modules/included_a.js: foo
./modules/included_b.js: foo

Actual Result: The page stays the same.

The page does display the correct result after manually saving main.js.

Issue 2: Deleting a file which matches the glob import

  1. npm run dev
  2. npm run addMod
  3. save main.js (see above why this is necessary)
  4. npm run delMod

Expected Result: This should hmr the file that contains the glob import (main.js)

./modules/included_a.js: foo

Actual Result:

[vite] (client) Pre-transform error: Failed to load url /modules/included_b.js (resolved id: /home/myuser/documents/github/public/vite-import-glob-repro/modules/included_b.js) in /home/myuser/documents/github/public/vite-import-glob-repro/main.js. Does the file exist?

The page does display the correct result after manually saving main.js.

System Info

System:
    OS: Linux 6.16 Manjaro Linux
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 19.10 GB / 31.23 GB
    Container: Yes
    Shell: 5.3.3 - /bin/bash
  Binaries:
    Node: 24.5.0 - ~/.volta/tools/image/node/24.5.0/bin/node
    Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
    npm: 11.5.1 - ~/.volta/tools/image/node/24.5.0/bin/npm
    pnpm: 10.17.0 - /usr/bin/pnpm
    bun: 1.2.22 - ~/.bun/bin/bun
    Watchman: 20250727.093445.0 - /usr/bin/watchman
  Browsers:
    Chromium: 140.0.7339.207
  npmPackages:
    vite: ^7.1.7 => 7.1.7

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: hmrp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions