-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
ESM Modules: ssrTransform blindly overwrites all functions named as an import instead of checking for a locally scoped function with the same name #4306
Comments
Here's the code in question: https://github.com/sveltejs/svelte/blob/ff6ce725bfdabba908690f4bae0b06a3f26da881/src/runtime/store/index.ts#L91 That gets compiled to
There are two functions named subscribe in this code and it appears |
Getting this issue. |
Getting issue as well when running a fork of svelte in my project. |
Describe the bug
See: sveltejs/kit#1947
ssrTransform
replaces allsubscribe
references defined withinwritable
with__vite_ssr_import_0__.subscribe
instead of using thesubscribe
function defined withinwritable
.Due to ssrTransform https://github.com/vitejs/vite/blob/main/packages/vite/src/node/ssr/ssrTransform.ts#L189,
writable in store/index.mjs is transpiled to become:
Reproduction
https://github.com/btakita/sveltekit-repro-subscribe-issue
svelte.config.js is forced to be an esm module by using a top-level await: https://github.com/btakita/sveltekit-repro-subscribe-issue/blob/main/svelte.config.js#L4
svelte/store writable is transpiled where subscribe is replaced by vite_ssr_import_0.subscribe https://github.com/btakita/sveltekit-repro-subscribe-issue/blob/main/src/hooks/index.ts
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: