Using esm for Svelte SSR works great, but when a Svelte component is the first thing to be required, esm does not seem to recognize import/export.
E.g this works great:
const { square } = require('./module.js');
require('svelte/ssr/register');
const app = require('./App.html');
console.log(app.render().toString());
But this gives rise to an error, like this basic repro illustrates:
// Works great if square is imported on its own first
// const { square } = require('./module.js');
require('svelte/ssr/register');
const app = require('./App.html');
console.log(app.render().toString());
The severside rendering scenario is blowing my mind.
I'd dig more info on how you use std/esm and Svelte to enable this rad workflow.
I've been using esm and Svelte as outlined in the docs for a quite a while with svelte-routing, and its been working perfectly, but I noticed that it stopped working if I moved/removed all regular imports before the first Svelte component import, const app = require('./App.html');.
It behaves the same way if I require the Svelte compiler in the same way as esm is required in the example, node -r @std/esm -r svelte/ssr/register index.js.
I don't have much knowledge of the inner workings of either the Svelte compiler or esm, so I'm not sure I can come with much valuable information.
I apologize. It seems like the exact module the Svelte component imports has to be imported, or it will not work.
// const { square } = require('./module.js');
// This doesn't work either. 'square' has to be imported.
const { cube } = require('./module2.js');
require('svelte/ssr/register');
const app = require('./App.html');
console.log(app.render().toString());
Ok @EmilTholin!
I'll dig into this today and get it working 馃槃
Found the issue. You're using an older version of @std/esm. It works with the current master branch. So I'm guessing will work with the latest release too 馃構
... You're right. That's embarrassing. I'm so sorry for wasting you time. Thanks @jdalton!
No problem @EmilTholin!
Thanks for hammering on @std/esm! Feel free to post bugs anytime.
Most helpful comment
The severside rendering scenario is blowing my mind.
I'd dig more info on how you use
std/esmand Svelte to enable this rad workflow.