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
TypeError: store.subscribe is not a function: When config.js is run as an ESM module by using top-level await #1947
Comments
I think (am not sure on this, please don't quote me) that you can actually simply export a promise here, so rather than a top level await wrap it all in a function and export the result of that function or simply use a promise with an async function:
|
@Crisfole Thank you for the workaround. On my project, I'm getting the same issue whether or not Referencing #1895 vitejs/vite#4230 |
Thanks @btakita for the detailed issue report. I can't say I 100% understand all the details having not had time to dig in, but it sounds like you're describing it as a bug in Vite? If so, it'd be best to file it over in the Vite repo as there will be more people there capable of understanding and fixing the issue. It may help it get looked at by the Vite team if you're able to reproduce it without SvelteKit involved (you can use https://github.com/sveltejs/vite-plugin-svelte/tree/main/packages/e2e-tests/vite-ssr as a starter project). After that, leave a comment on vitejs/vite#4230 pointing to the Vite issue to help make sure we keep track of it and can help get it prioritized in discussions with the Vite team |
Closing in favor of the Vite issue since I don't think there's anything we can do on the SvelteKit side: vitejs/vite#4306 |
Getting this issue was well when running master fork of svelte. |
Describe the bug
When
svelte.config.js
is forced to be an esm module by using a top-levelawait
and withinsrc/hooks/index.ts
:import svelte/store
loads the esm version ofsvelte/store/index.mjs
.ssrTransform
in vite overwrites the transpiledwritable
function to referencesubscribe
that is imported frominternal/index.mjs
. This causes the returnedWritable
store fromwritable
to have the incorrect definition ofsubscribe
.Due to
ssrTransform
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/ssr/ssrTransform.ts#L189,writable
instore/index.mjs
is transpiled to become:writable(null).subscribe
does not operate correctly sincesubscribe
frominternal/index.mjs
replaces thesubscribe
defined within thewritable
function.Reproduction
https://github.com/btakita/sveltekit-repro-subscribe-issue
svelte.config.js
is forced to be an esm module by using a top-levelawait
: https://github.com/btakita/sveltekit-repro-subscribe-issue/blob/main/svelte.config.js#L4svelte/store
writable
is transpiled wheresubscribe
is replaced by__vite_ssr_import_0__.subscribe
https://github.com/btakita/sveltekit-repro-subscribe-issue/blob/main/src/hooks/index.tsLogs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: