Skip to content
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

SyntaxError: Unexpected token 'export' #238

Open
krishnaTORQUE opened this issue Feb 9, 2023 · 4 comments
Open

SyntaxError: Unexpected token 'export' #238

krishnaTORQUE opened this issue Feb 9, 2023 · 4 comments

Comments

@krishnaTORQUE
Copy link
Collaborator

export { default as Router } from "./Router.svelte";
^^^^^^

SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1088:15)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object. (/home/krishna/Project/svelte_test/src/App.svelte:5:33)
at Module._compile (node:internal/modules/cjs/loader:1159:14)

Node.js v18.12.1

@EmilTholin
Copy link
Owner

EmilTholin commented Feb 10, 2023

Hi @krishnaTORQUE!

This might be related to #237. Could you possibly try the potential solution outlined in that issue and name the entry file to index.mjs in node_modules and see if the error goes away? Then that might be the change that is needed.

@krishnaTORQUE
Copy link
Collaborator Author

@EmilTholin
I tried & it worked but svelte/register does not have mjs support.

@atsepkov
Copy link

@krishnaTORQUE did you ever find a solution? I need SSR for SEO support and since this doesn't look like it's going to get fixed, I've started looking for alternatives to this library.

@krishnaTORQUE
Copy link
Collaborator Author

krishnaTORQUE commented Jul 15, 2023

Hi @atsepkov

The solution which I have implemented is quite hard & only works on linux.
I am using rust in the backend & this is how I SSR. Rust get data from node & render.
Here you go

# src/pages/
- Home.svelte
- About.svelte

# src/App.svelte
<Router>
...
</Router

# src/ssr.cjs
require("svelte/register");

const args = process.argv.slice(2);

/**
 * Args *
 * @Param 0 Page/File Name Only
 * @Param 1 Props in JSON String Format
 */
const page = require(`./src/pages/${args[0]}.svelte`).default;

const render = page.render(args[1] ? JSON.parse(args[1]) : {});

console.log(JSON.stringify(render));

# usage
- node src/ssr.cjs Home ‘{}’
-  node src/ssr.cjs About ‘{"name": "Krishna"}’

If you are using vite then the solution will be slightly different. Vite has some cool features for SSR & Typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants