Skip to content

addWatchFile can not be used to watch files outside of the module graph #7024

@zauni

Description

@zauni

Describe the bug

When I am writing a plugin and using "addWatchFile" inside the plugin to watch files which are not imported in some JS file, then Vite is tracking that the file has changed, but doesn't reload because of the message "no modules matched"

For example I added some-other-file.yaml with "addWatchFile" and then Vite in debug mode logs this on changes:

vite:hmr [file change] some-other-file.yaml +42m
vite:hmr [no modules matched] some-other-file.yaml +1ms

In the reproduction you have to do npm run dev and then change the file some-other-file.yaml to see this output.

If I do this in rollup, it is doing the reload on file changes. But Vite is somewhere loosing the info of the file path inside the module graph.

This was noticed when developing the rollup-plugin-openapi

Reproduction

https://stackblitz.com/edit/vitejs-vite-wuaaxt?file=vite.config.js

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 68.09 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/Library/Caches/fnm_multishells/14259_1645436772510/bin/node
    npm: 8.3.1 - ~/Library/Caches/fnm_multishells/14259_1645436772510/bin/npm
  Browsers:
    Chrome: 98.0.4758.102
    Firefox: 97.0
    Firefox Developer Edition: 98.0
    Safari: 15.3
npmPackages:
    vite: ^2.7.2 => 2.8.4 

Used Package Manager

npm

Logs

vite:hmr [file change] some-other-file.yaml +42m
vite:hmr [no modules matched] some-other-file.yaml +1ms

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions