-
Notifications
You must be signed in to change notification settings - Fork 63
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
Pancake doesn't work with node due to using ES Modules (SSR) #7
Comments
|
Okay I started fresh using oldsrc % node index.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module '@sveltejs/pancake'
Require stack:
- /Users/jordan/git/DTE/svelte-tests/ssr2/my-svelte-project/src/oldsrc/App.svelte
- /Users/jordan/git/DTE/svelte-tests/ssr2/my-svelte-project/src/oldsrc/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/jordan/git/DTE/svelte-tests/ssr2/my-svelte-project/src/oldsrc/App.svelte:5:30)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.require.extensions.<computed> [as .svelte] (/Users/jordan/git/DTE/svelte-tests/ssr2/my-svelte-project/node_modules/svelte/register.js:49:17)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1040:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/jordan/git/DTE/svelte-tests/ssr2/my-svelte-project/src/oldsrc/App.svelte',
'/Users/jordan/git/DTE/svelte-tests/ssr2/my-svelte-project/src/oldsrc/index.js'
]
} |
How and where did you import it? |
@Vehmloewff, I must be missing some basic understanding of how this works. |
Some extra info: server side rendering a regular Svelte component (without pancake) to html and css works just fine without Rollup. I just run <main class="svelte-1tky8bj">
<h1 class="svelte-1tky8bj">Hello undefined!</h1>
<p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p>
</main> |
True, if you are using |
Just to be clear, what does the relevant part of your |
Okay that makes sense, but how is it intended to be used for Server Side Rendering then? The surge site says "Pancake is designed with server-side rendering in mind". Maybe it's just not finished yet? I know this is an early project, I'm just excited to try it out - it would be perfect for my use case :) My entire index.js is require('svelte/register');
const App = require('./App.svelte').default;
const { head, html, css } = App.render();
console.log("TCL: head, html, css", head, html, css) |
Does |
|
Then this package either needs a |
I'll try that out in a fork and see if i can get it to work |
When I add Also strangely, the stack trace reports the wrong line number in the svelte file as the cause. I will continue to investigate. |
So it appears that you can't |
Yeah, this sounds like a pretty nasty bug. |
Note, however, that using svelte for SSR does work fine, it's only Pancake that causes an issue because Pancake uses ES Modules. |
You can try Right now modules are a total mess in node, and I say that with the biggest anger I can muster. An absolute mess. |
I just encountered the same issue. A quick hack that worked for me was to just add |
None of the solutions above seem to work for me.
I don't know much, but reading this convo this makes sense. What is needed for this, rename .mjs -> .js? Also I've made a community fork (and an issue about it) if you want to fix this and get PR accepted (or be a contributor why not). |
Using Using a bundler to compile for SSR will solve this issue without any changes. |
@pngwn do you have an example for how you would set up a bundler to compile for SSR successfully? |
See this comment for a solution: sveltejs/svelte#5185 (comment) |
@mhkeller, thanks! Linking directly to his PR here: |
This project has a fancier ssr rendering setup that you may want to look at too https://github.com/russellgoldenberg/svelte-starter/ |
The Real Problem
Pancake works fine when used with a bundler, but svelte/register doesn't work when trying to run directly with node. This is because ES Modules need to be imported (as opposed to
require()
) and because imports are asyncronous, so the.svelte
extension isn't registered in time.Original Issue
Hey Rich,
Love this library. I'm trying to get SSR working with the following from the svelte docs:
index.js
and App.svelte contains your Life Expectancy chart from https://pancake-charts.surge.sh/
However, when I run
node index.js
, I get:Error: Cannot find module '@sveltejs/pancake'
I'm on Node v13.8.0
Am I missing a preprocessing step? The example makes it look like I can just require the .svelte file as i do in index.js above.
How do I render a chart on the server-side via node?
The text was updated successfully, but these errors were encountered: