-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
import.meta.glob from node_modules caches project files incorrectly #19632
Comments
the reproduction does not work, the Please provide a reproduction that depicts the exact problem you describe and also why you believe this to be a bug in vite. Is this in a monorepo setup or do you intend to publish a package where My initial thought on this is that import.meta.glob shouldn't work at all in node_modules, imports in dependencies shouldn't depend on a bundler and even if it did work, it should only be possible to import from declared dependencies or the packages import map, not the apps To make the lib not depend on the app, you could change the setup so that the app does the globing and passes the result into the library. |
See the
In summary, if a library imports files from your project like this:
And you use it like this:
(and have Then it caches
It's a published package but currently to a private repository for internal use only.
This all works and we've been using it for some time - except for the caching issue which we've only just managed to figure out.
This is less a library and more a "framework" - the framework is actually in control and calls down to the project rather than the other way around. However, I don't mind if you want to say this isn't supported - we've already got tricks to generate boilerplate files in the project to invert the control and make it look more "normal" to vite, so we could do similar to avoid this issue. |
personally i think its odd to import app code into a library/framework that way as it creates an unexpected implicit tight coupling in the wrong direction. The optimizer for one does not expect this to happen and as such can't know if a local file matched by a glob has changed since it was last optimized. You might be able to work around this by putting |
We're already using I will close as unsupported. |
Describe the bug
If a library in
node_modules
usesimport.meta.glob
, any files loaded by the glob are loaded using the same caching policy as the library.For example, in [email protected]:SystemParadox/vite-cache-issue.git, the network tab of devtools shows that
mylib.js
andfoo.svelte
both use?v=2061e277
and are both cached aggressively.This means that if for example
foo.svelte
is loaded initially but then something causes a dependency reoptimisation reload, then the browser will use its cached version offoo.svelte
which is incorrect.Combined with sveltejs/vite-plugin-svelte#1032 this also results in svelte styles randomly disappearing in our application.
Reproduction
[email protected]:SystemParadox/vite-cache-issue.git
Steps to reproduce
pnpm i
pnpm start
foo.svelte
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: