-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watch dynamically imported files not detected automatically and cached #5429
Comments
Thanks for the concise reproduction. It might look surprising, but I think it's mostly working as intended. Let me check one by one.
This looks like because of "too dynamic" dynamic import, which is not statically analyzed by Vite/Vitest, so module graph cannot track "test file -> foo.ts" dependency to trigger auto re-run. I made a quick example to show the difference here. Given these two tests, // dynamic-ok.test.ts
await import('../src/bar');
// dynamic-not-ok.test.ts
await import(String('../src/bar'));
This one looks weird, but maybe a different issue, something related to deprecated Actually this might be a bug, so this needs to be investigated further. Regarding point 4, do you actually use this "too dynamic" form of dynamic import? I think supporting this is out-of-scope for now. But depending on the use case, there might be a workaround, for example, using Vite's import glob |
Thanks for the quick reply, we do actually use a lot of those dynamic loading but only directly to JS for now(I could get into the details but not sure this is really relevant, let me know if you want to), not having the auto rerun of I'll look into |
Does |
It doesn't surprisingly not even in the TS case, I updated the repro abvoe with
or with
neither seems to retrigger the auto run |
I thought that would work... Weirdly it looks like it's not possible to make Vite's watcher to look for changes in Even something like this doesn't work: export default defineConfig({
server: {
watch: {
ignored: ["**/node_modules/**"],
},
},
test: {
watchExclude: ["**/node_modules/**"],
forceRerunTriggers: ["**/dist/**"],
},
}); The watcher here still has some hardcoded values in vitest/packages/vitest/src/node/core.ts Line 742 in 0ec4d0e
The |
I see so if I add this to the config then the js reloads fine(though unsure if this is a viable workaround, feel like it should as vitest doesn't actually write to the outDir) build: {
outDir: 'dummy',
}, also noticed that |
Setup a workaround for the fact that vitest(vite underneath) doesn't ever want to reload files in the outDir vitest-dev/vitest#5429 as the outDir isn't actually used in vitest(as far as I understand) this is just an ok workaround.
Describe the bug
When dynamically importing JS or TS files (
await import
with a resolved value) vitest watch doesn't pickup on change automatically and in the case of JS files that are in thedist
directory it won't reload at all(Keeps the original code).The same also happen when working in a vitest workspace and trying to dynamically import JS files from another dependency
dist
folder.Reproduction
Stackbliz url
npm run watch
to also build the TS -> JS indist
dir.export const test = (n: number) => n * 4;
TS
import ones seems to be reloaded. JS files are not even though I reconfigured theexclude
to not excludedist
folder. If you change so that TS output dir iscustomDist
instead ofdist
then the JS files do get reloaded correctly.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: