-
Notifications
You must be signed in to change notification settings - Fork 201
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
Nested Component imports via MDX aren't JSX transformed #309
Comments
Thanks for opening this issue and providing a minimal and straightforward repro! Looking into it! 🕵️ |
After further investigation it seems like this might actually be a problem in esbuild which is a transitive dependency of Contentlayer as its a dependency of mdx-bundler which Contentlayer currently relies on. (Note I'm not 100% sure this is actually a bug in esbuild - that's just my current hypothesis.) Unfortunately I don't have enough capacity right now to create a reproduction of the underlying upstream problems. My suspicion is that other tools like mdx-bundler also suffer from this same problem. I'd greatly appreciate if someone wants to help out with investigating this further but I don't think this is a problem within Contentlayer directly. As a temporary workaround you could use a different "MDX strategy" by avoiding direct const MyButton: React.FC = () => <button>Click me</button>
const Page: React.FC<{ post }> = ({ post }) => {
const MDXContent = useMDXComponent(post.body.code)
return (
<div>
{/* Some code ... */}
<MDXContent components={{ MyButton }} />
</div>
)
} Note: Implementing #298 might make this problem either more obvious or obsolete. |
@andy-stewart-design did you later resolve this? |
Update: it's indeed a bug/limitation in esbuild: |
Hey @schickling is this problem fixed? |
I'm running into problems when trying to import components inside a
.mdx
file, and more specifically when the imported component also imports other components. What I want to be able to doImporting the component by starting with the base path works as long as it is a standalone component and does not import another component. If that component does include an import statement, I get the following error:
The weird thing is, I'm having this issue on a project that I just spun up this morning, but not on a project that was created several months ago, even though they are using the same version of Next and ContentLayer. This could mean that it's user error, but I've looked in detail at the setup/configs for both projects and cannot find the issue.
Repro
Attempted Solutions:
contentType
asmdx
. error - SyntaxError: Unexpected token '<' #180makeSource
as described here, but that did not resolve the issue. Can't import components that use external packages #302The text was updated successfully, but these errors were encountered: