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

Bright can't be used from dynamically imported module #18

Open
altano opened this issue May 21, 2023 · 1 comment
Open

Bright can't be used from dynamically imported module #18

altano opened this issue May 21, 2023 · 1 comment

Comments

@altano
Copy link
Contributor

altano commented May 21, 2023

Here's a repro of the issue: https://codesandbox.io/p/sandbox/2spsii?file=%2Fapp%2Fmdx%2F%5Bslug%5D%2Fpage.tsx%3A10%2C19

(click the link when it's opened)

Error:

Error: This module cannot be imported from a Client Component module. It should only be used from a Server Component.

The problem appears to be that the Bright component doesn't work when dynamically imported from a server component. It thinks it is in a client component even though it isn't.

My code works fine without Bright. I can dynamically import the mdx component from my server component.

@pomber
Copy link
Contributor

pomber commented May 22, 2023

Strange. That error comes from the server-only package (a dependency of Bright) developed by the React team. For me, your code makes sense and it should work, but maybe there is some limitation that we are not seeing.

This, for example, works:

export default async function Article() {
  const { Code } = await import(`bright`);

  return (
    <article>
      <Code lang="js">console.log(1)</Code>
    </article>
  );
}

So I'm suspecting that it's some problem with nextjs' mdx plugin. Need to investigate more.

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

2 participants