question-mark
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.

Unrecognised components

See original GitHub issue

(Not sure if this should live here or on xdm?)

  • mdx-bundler version: ^4.1.1
  • node version: v16.1.0
  • npm version: 7.11.2

On NextJS, pages/index.js

import React from 'react';
import path from 'path';
import { bundleMDX } from 'mdx-bundler';
import { getMDXComponent } from 'mdx-bundler/client';

process.env.ESBUILD_BINARY_PATH = path.join(
  process.cwd(),
  'node_modules',
  'esbuild',
  'bin',
  'esbuild'
);

export default function Home({ code }) {
  const Component = React.useMemo(() => getMDXComponent(code), [code]);

  return (
    <div>
      <Component />
    </div>
  );
}

export async function getStaticProps() {
  const result = await bundleMDX(`
    ---
    title: Foo!
    ---

    Foo Component
    
    <Foo />
  `);

  return {
    props: {
      code: result.code
    }
  };
}

What you did:

My remote MDX content contained a component which I did not expect (old component no longer in use, but still in the old MDX file). When using mdx-bundler with NextJS, this throws errors and the page is unable to compile/render.

I was previously using next-mdx-remote, using the v2 branch (so mdx v2 under the hood), and components which were not recognised were simply removed.

What happened:

With a single unrecognised component, I’m getting a lot of these logs:

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
    at y (eval at getMDXComponent (/.../node_modules/mdx-bundler/dist/client.js:37:50), <anonymous>:3:1022)

Reproduction repository:

https://stackblitz.com/edit/nextjs-cmdd2t?file=pages/index.js

Problem description:

Add an unrecognised component, and an error will be thrown:

---
title: Foo
---

Foo Component...!

<Foo />

Suggested solution:

Either remove the Foo component from the tree or allow a way to hook onto unrecognised components and display something?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
Arcathcommented, Jul 12, 2021

I think mdx-bundler is working as intended here. If I used a component that I hadn’t imported I’d want an error to be thrown so I could fix it, I wouldn’t want my site to build as normal and just skip it out.

If you want to implement this functionality I’d suggest looking at a remark/rehype plugin for xdm.

0reactions
k1sul1commented, Feb 21, 2022

I would argue that MDX is not (always) literate programming. I’m currently working on a case where SWIM updates a site periodically. They don’t know how to code, but they can read instructions like “You can also use <Stuff />, <Stuff2 /> in the markup”.

They are not comfortable with the idea of writing (J/T)SX, but markdown they can handle. They can also handle some sprinkled in components.

It’d be nice if there was an option to provide a fallback component, just so I could have the live preview show where exactly the non-computer savvy user made the mistake. Right now it seems I’m forced to resort to… this.

image

I don’t know how any of this actually works, but it’d be nice to have support for this use case. It’s not necessary, but it’d be nice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unrecognised Components of the Chronicon Budense | 13 | Studies ...
This chapter presents the Hungarian Chronicles, lay and ecclesiastical, of the mediaeval period. Their interest and importance seemed to him to justify far....
Read more >
Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >
Section 302 notification requirements and mixtures with ...
Section 302 notification requirements and mixtures with unknown components. Are facilities exempt from Section 302 notification requirements ...
Read more >
Component Identification - Sonatype Help
When a component has a match state of Unknown, it usually means that Lifecycle wasn't able to match the component to other components...
Read more >
Couldnot Open Key UNKNOWN\Components\. when install ...
Couldnot Open Key UNKNOWN\Components\. when install SQL2019. Hi ,. Uninstalled SQL 2016 version completely and install SQL 2019 Developer ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found