-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
a script tag referencing node_modules does not get browserHash injected causing double-instantiation #9828
Comments
Related issue, we may have a regression here #9661. We need to hash files (with For the example that Rich added, if 'foo' is in optimizeDeps exclude, it may still import other dependencies (that have been optimized) so we still need to have a |
It is a bug, for reference, I added an explanation of why we need version queries in direct node_modules imports in the description of: |
Sveltekit was fixed by #9848 but the repro in the OP is not fixed. This is happening because we are not injecting browserHash to script tags referencing a file in node_modules. (https://discord.com/channels/804011606160703521/804439875226173480/1172385782007353344) A workaround is to use I guess this would also be fixed if we make bare specifiers work in HTML in dev (#12260). Though I'm not sure if we are going to support that. |
Describe the bug
I'm not sure if this is a bug or expected behaviour, but it's left me scratching my head and I'd love to know if there's a workaround at the very least.
When a module is imported via a project-relative URL (
/node_modules/foo/index.js
) and via a package name (foo
), Vite resolves the latter to/node_modules/foo/index.js?v=xyz123
, which causes the module to be instantiated twice. (In this example,optimizeDeps.exclude = ['foo']
.)This is causing headaches for SvelteKit users, as it causes failed
instanceof
checks. It doesn't happen when the package in question is installed outside the directory (e.g. in a workspace root), because in that case both references are resolved to/@fs/path/to/project/node_modules/foo/index.js
.Reproduction
https://github.com/Rich-Harris/vite-browserhash-repro
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: