code-hike / codehike

Marvellous code walkthroughs
https://codehike.org
MIT License
4.39k stars 135 forks source link

Cannot execute mdx `run` on string with mdx included codehike code in next.js frontend #247

Closed kliukovkin closed 1 year ago

kliukovkin commented 1 year ago

The issue is with such sample:

import { run } from "@mdx-js/mdx";
import * as runtime from "react/jsx-runtime";
import { compile } from "@mdx-js/mdx";
import { remarkCodeHike } from "@code-hike/mdx";

const textTest1 = `
  \`\`\`python hello.py
  # mark[16:24]
  print("This is Code Hike")
  \`\`\`
`;

const code = await compile(textTest1, {
  outputFormat: "function-body",
  useDynamicImport: true,
  remarkPlugins: [[remarkCodeHike]],
})

const { default: Component } = await run(code, runtime)

console.log(Component);

When executing this code on backend everything works fine and I see in the console:

[Function: MDXContent]

But the problem is that I'm running compile1 on the backend and return to the frontend string with code. Then, when I'm trying to call run I faced with an error:

Screenshot 2022-07-28 at 14 29 55

@pomber Do you know any workaround or how to solve this issue?

pomber commented 1 year ago

You probably need to disable CodeHike's autoimport. See #222 for a similar issue.

Let me know if it doesn't work.

kliukovkin commented 1 year ago

That works! Thank you @pomber !