a script tag referencing node_modules does not get browserHash injected causing double-instantiation #9828
Labels
feat: deps optimizer
Esbuild Dependencies Optimization
feat: html
has workaround
p2-edge-case
Bug, but has workaround or limited in scope (priority)
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: