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 components (in MDX) that use external packages doesn't work #157

Closed
olayway opened this issue Sep 9, 2022 · 1 comment · Fixed by #182
Closed

Importing components (in MDX) that use external packages doesn't work #157

olayway opened this issue Sep 9, 2022 · 1 comment · Fixed by #182
Assignees
Labels
bug Something isn't working

Comments

@olayway
Copy link
Member

olayway commented Sep 9, 2022

@khalilcodes, @rufuspollock it seems importing components that depend on external packages doesn't work indeed 😞 I believe it has to do with Contentlayer's configuration/usage of mdx-bundler. When you actually define the component and import it's dependencies directly in MDX file (not import them from a file) everything works. So it has sth to do with imports resolution I guess. Anyways, I've created an issue in Contentlayer's repo for that: contentlayerdev/contentlayer#302

You can also test it yourself. I've added relevant tests to /content/test/components-import.md so that Contentlayer's team can reproduce the issue.

I think we should also get acquainted with Contentlayer's source code sometime, and also with the docs of mdx-bundler', which they are using under the hood, so that it's not a complete black box for us.

Originally posted by @olayway in #111 (comment)

@olayway olayway moved this to 🆕 New in Flowershow Backlog Sep 9, 2022
@olayway olayway added the bug Something isn't working label Sep 9, 2022
@rufuspollock rufuspollock moved this from 🆕 New to 🔖 Ready in Flowershow Backlog Sep 13, 2022
@rufuspollock rufuspollock moved this from 🔖 Ready to ⛔ Blocked in Flowershow Backlog Sep 14, 2022
@olayway olayway moved this from ⛔ Blocked to 🏗 In progress in Flowershow Backlog Sep 23, 2022
@olayway olayway moved this from 🏗 In progress to 👀 In review in Flowershow Backlog Sep 23, 2022
@rufuspollock
Copy link
Member

We have a resolution thanks to a comment from @timlrx

Hi Ola,

That's because the import is not being resolved properly. contentlayer uses the content file directory as the cwd but node_modules is not present in the folder and thus the import node resolution fails. One workaround is to define cwd to the current directory:

export default makeSource({
    mdx: {
      cwd: process.cwd(),
  }
})

and modify the imports relative to the root folder:

import LibTest from "./components/custom/LibTest.jsx"

Hope that helps!

Repository owner moved this from 👀 In review to ✅ Done in Flowershow Backlog Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants