Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing mdx files from node_modules doesn't work

See original GitHub issue

Hi ! Thanks for this neat tool !

I’d like to use it to do some transclusion of Mdx files, some of which I would like to manage as individual npm packages.

My understanding of the comment below is that this should work out of the box:

But I can’t make it work …

I’ve created a new test case in my fork to illustrate:

test('bundles mdx files from node_modules', async () => {
  const mdxSource = `
import MdxTestData from 'mdx-test-data'
The content below was imported from an MDX File in node_modules.
<MdxTestData />

  const result = await bundleMDX(mdxSource, {
    files: {},

  const Component = getMDXComponent(result.code)

mdx-test-data is a package that simply exposes README.mdx in the main field of package.json

And running this test yields this result:

   FAIL  "bundles mdx files from node_modules"
    Build failed with 1 error:
__mdx_bundler_fake_dir__/_mdx_bundler_entry_point.mdx:2:24: error: No loader is configured for ".mdx" files: node_modules/mdx-test-data/README.mdx

    __mdx_bundler_fake_dir__/_mdx_bundler_entry_point.mdx:2:24: error: No loader is configured for ".mdx" files: node_modules/mdx-test-data/README.mdx
    at failureErrorWithLog (C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:1432:15)
    at C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:1114:28
    at runOnEndCallbacks (C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:912:47)
    at buildResponseToResult (C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:1112:7)
    at C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:1219:14
    at C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:603:9
    at handleIncomingPacket (C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:700:9)
    at Socket.readFromStdout (C:/Users/gaelh/dev/mdx-bundler/node_modules/esbuild/lib/main.js:570:7)
    at Socket.emit (events.js:315:20)

Am I missing something ? Is there another way of importing mdx files from node_modules ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

Arcathcommented, May 2, 2021

@gaelhameon returning an empty object should work as I interpret the docs.

I have seen some behaviour in esbuild where if a plugin returns anything it gets first dibs on the next phase, but that should still have passed over to xdmEsbuild when the inMemory onLoad callback returned {}

Bit strange.

gaelhameoncommented, May 12, 2021

@Arcath , yes, 4.0.0 has fixed this for me. Thanks !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting MDX
This article goes through several common problems and errors that might occur when using MDX. To understand how the MDX format works, ...
Read more >
Cannot find module '@mdx-js/mdx' - Gatsby - Stack Overflow
You can check this with import {<name>} from '@mdx-js/mdx' . You can also check this with navigating to node_modules/@mdx-js/mdx directory. You ...
Read more >
MDX and React - Docusaurus
Docusaurus has built-in support for MDX v1, which allows you to write JSX within your Markdown files and render them as React components....
Read more >
@mdx-js/mdx - npm
Typically, import (or export … from ) do not work here. They can be compiled to dynamic import() by passing options.useDynamicImport . file....
Read more >
Mdx-bundler NPM -
One of mdx-bundler's dependancies requires a working node-gyp setup to be able to ... If your MDX doesn't reference other files (or only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found