-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Closed
Labels
Description
Describe the bug
The observed bug is that import.meta.glob('...')
does not detect newly added files under some circumstances.
I've only seen this during SSR and using a pattern like ..../*.(js|ts)
. It works when using ..../*.[jt]s)
instead.
I think the reason is that import.meta.glob
uses fast-glob
to match files, which internally uses micromatch
.
However, the watcher uses minimatch
instead to track new files. Apparently, the syntax of those two is different.
See this example:
const minimatch = require("minimatch")
const micromatch = require("micromatch").isMatch
const newFile = 'pages/name.server.jsx'
const pattern = 'pages/**/*.server.(jsx|tsx)'
console.log(
minimatch(newFile, pattern), // false
micromatch(newFile, pattern) // true
)
Related issue: #2734
Reproduction
https://stackblitz.com/edit/vitejs-vite-5mh3tc?file=entry-server.js
- Run
npm run dev
- Add new JS or TS files to
files
directory. The view won't be refreshed automatically. - Toggle the glob comments in
entry-server.js
. - Add files again. The view should now refresh.
System Info
System:
OS: macOS 12.0.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 3.98 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.5.0 - /opt/dev/sh/nvm/versions/node/v16.5.0/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 7.19.1 - /opt/dev/sh/nvm/versions/node/v16.5.0/bin/npm
Watchman: 2021.10.18.00 - /usr/local/bin/watchman
Browsers:
Chrome: 95.0.4638.54
Safari: 15.1
npmPackages:
vite: ^2.6.0 => 2.6.13
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.