Cannot run compiled code in my client #2279
-
I'm trying to compile Markdown and run it in my sveltekit client. I'm currently stuck on the problem that the Would be very grateful for any pointers! Here's an example of a svelte file that gives me this error: <script lang="ts">
import { onMount } from "svelte";
import { compile, run } from "@mdx-js/mdx";
import * as jsxRuntime from "svelte-jsx/jsx-runtime";
let compiled: string = "";
const testCompile = async () => {
try {
compiled = String(
await compile("#This is a title", {
format: "md",
jsxImportSource: "svelte-jsx",
development: false,
})
);
} catch (error) {
console.log("failed to compile", error.message, error);
}
};
let ran: any = undefined;
const testRun = async () => {
if (compiled) {
console.log("Attempting to run compiled:", compiled);
try {
const { default: Component } = await run(compiled,
jsxRuntime
);
ran = Component;
} catch (error) {
console.log("failed to run", error.message, error);
}
}
};
const test = async () => {
await testCompile();
await testRun();
};
onMount(test);
</script>
{"I want to render the component here eventually"} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You are not compiling correctly. Please see the docs on how to compile and run things: https://mdxjs.com/packages/mdx/#runfunctionbody-options. If you are compiling and running, use evaluate: https://mdxjs.com/packages/mdx/#evaluatefile-options. |
Beta Was this translation helpful? Give feedback.
-
I'm also having problems with run and runSync, and I'm going to switch to using
But in terms of effort (from the user perspective), these cases seem to be far apart. Is this because |
Beta Was this translation helpful? Give feedback.
You are not compiling correctly. Please see the docs on how to compile and run things: https://mdxjs.com/packages/mdx/#runfunctionbody-options.
If you are compiling and running, use evaluate: https://mdxjs.com/packages/mdx/#evaluatefile-options.