-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
Not possible to use svelte/register server-side builds with a Svelte component exported from an esm module? #5185
Comments
I think this is not related to svelte. Please tell me if it helped. |
Thanks. If I run |
hmm... I'll try doing some research on this. |
Here's the same example working in the REPL: https://svelte.dev/repl/47e73637efe44b3e87962343b08adf77?version=3.24.0 |
Same issue with some discussion: Rich-Harris/pancake#7 |
Well, |
Yeah it sounds like there's not a corresponding feature in Node's ESM support yet, which would be required for this. |
@Conduitry thanks for taking a look. Do you think there is any build remedy (either through some combination of using the |
@Rich-Harris put together a solution for this involving bundling into CommonJS. Linking it here: mhkeller/lc-ssr-test#1 |
@mhkeller For this case i've used
Registering the extension , all ES6 modules should follow this convention
Also a dirty one here to just make it work :
My case was simple and it solved all the problems i had with svelte/register. |
My problem with this was solved by compiling it ahead of time per the above link. @Conduitry unless you think this should be handled inside of svelte/register, feel free to close this issue. |
If/When Node's ESM implementation adds the loader hooks mentioned in their docs, maybe we can revisit this, but for now it doesn't seem like there's anything for Svelte to do here, |
@Conduitry looks like it is possible now: |
It's in stage 1 (experimental), so nothing that can be relied on I'd say |
There's a note on the page you linked to which explicitly says that the API will change, so no, we don't want to use that. |
Yes, just I wanted to point out, that the feature will be probably available to be used soon (after experimental stage). For now, we need just wait. |
import { createRequire } from "module"
const require = createRequire(import.meta.url)
const props = {}
const App = require("./src/App.svelte").default
const { html, css, head } = App.render(props)
... unfortunately import doesn't work inside required any svelte-to-cjs transpiller middleware? |
What is a working solution? not sure I saw one. |
@malindsay As mentioned above, there is no solution until Node officially supports loaders, which is the equivalent of |
So we really don't have a svelte ssr solution, or can someone point me into a solution that works at moment? if not resolved, why was this closed? |
@malindsay this was my solution but this was before svelte kit #5185 (comment). im not sure if this is a current problem using svelte kit though. i put together a demo with my library and ssr worked without a problem https://github.com/mhkeller/layercake-template-sveltekit-test |
There are many ways to achieve Svelte SSR, |
@malindsay I implemented this functionality on esm module by experimental esm transpiler loader. It worked, but anyway, I decided to dig into how Sapper works, look various already implemented SSRs, and find out it's not that hard to do it by yourself, it just need some research. Although, I would love some more SSR documentation, due I can't use SvelteKit or Sapper. |
I am facing the same issue. |
I'm not sure if this is a bug or an unsupported pattern. I'm trying to use
svelte/register
to do server-side rendering of a Svelte component. Here are the files. Basically I'm importing a Svelte component via.mjs
file that exports it. These files are also up at this reproduction repo.<!-- ./components/Test.svelte --> Test
When running
node index.js
I get the following error:I also tried running it with
node -r esm index.js
but that doesn't fix it. When I run this code in dev mode, however, the components load fine. Is this a limitation of svelte/register or do I have to do bring in some other third-party solution to smooth over the esm import? I would think that if the normal dev mode can handle it, there would be parity in server-side mode.Thanks for taking a look.
The text was updated successfully, but these errors were encountered: