esm/Svelte SSR does not always recognize import/export

Created on 23 Feb 2018  路  7Comments  路  Source: standard-things/esm

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());
invalid

Most helpful comment

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.

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kherock picture kherock  路  3Comments

MVSICA-FICTA picture MVSICA-FICTA  路  3Comments

Mensu picture Mensu  路  3Comments

Pokute picture Pokute  路  3Comments

OmgImAlexis picture OmgImAlexis  路  3Comments