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

Importing TSX / JSX component directly into MDX file. #286

Closed
rajuashok opened this issue Jul 8, 2022 · 2 comments
Closed

Importing TSX / JSX component directly into MDX file. #286

rajuashok opened this issue Jul 8, 2022 · 2 comments

Comments

@rajuashok
Copy link

Hi there.
I'm using this version:
"next-mdx-remote": "^3.0.8"

I'm trying to import a component directly into my .mdx file like so:

import LeagueWithTeam from '../components/LeagueWithTeam';

<Fragment>
  <LeagueWithTeam
  region={region}
  lng={lng}  />
</Fragment>

The file components/LeagueWithTeam.tsx looks roughly like this:

import React from 'react'

const LeagueWithTeam = () => {...}

export default LeagueWithTeam

But when I build this I get the following error:
Component LeagueWithTeam was not imported, exported, or provided by MDXProvider as global scope

Is it not possible to import components directly into MDX files?

@noahlst
Copy link

noahlst commented Jul 8, 2022

Not with this package implementation.

We have to pass components through <MDXRemote>, like this:

import LeagueWithTeam from "components/LeagueWithTeam"

export const components = {LeagueWithTeam}

export default function Page() {
  return (
    <MDXRemote components={components} />
  )
}

This is outlined in the package Readme.

@BRKalow
Copy link
Contributor

BRKalow commented Jul 20, 2022

As mentioned above, imports are not supported in next-mdx-remote as we treat the content as data, so resolving imports is a non-trivial problem.

related to #48 #143

@BRKalow BRKalow closed this as completed Jul 20, 2022
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