MDX error messages #1775
-
Hey, I'm evaluating MDX for potential use as an alternative syntax for Nota, my academic paper framework. One big issue that I've seen so far is how MDX handles certain kinds of errors. Let's say I forget an import for a custom component, such as: import {Foo} from "foo";
<Foo />
<Bar /> <-- uh oh! From what I understand reading the output, MDX will resolve The error isn't helpful since it just says "somewhere in the document, you have a null element." Are there ways to improve this? Either during the MDX pass to flag such issues, or better source-mapping so React can point to a specific spot where the error arises? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
@willcrichton you may want to try out MDX 2 (currently at release candidate 1 https://github.com/mdx-js/mdx/releases/tag/2.0.0-rc.1), which includes better source mapping.
As you noted, this error is not coming from MDX, it comes from React (or could come from Preact or Vue). |
Beta Was this translation helpful? Give feedback.
-
What is the other syntax?
Not exactly. See How MDX works for the output.
Unfortunately it is not known at compile time whether this is an issue. In MDX 1, there is an error. It works something like this: const _components = Object.assign({
p: "p",
// …
Bar: () => console.warn('`Bar` is not defined')
}, props.components) This is a) not consistent with react and similar, because they throw for missing components, b) doesn’t work well with objects. In JSX you can use object access notation like this:
JSX dot notation isn’t limited to one component on an object, but can be long: I can see a couple ways to improve this:
|
Beta Was this translation helpful? Give feedback.
What is the other syntax?
Not exactly. See How MDX works for the output.
Bar
can be passed or provided.Unfortunately it is not known at compile time whether this is an issue.
In MDX 1, there is an error. It works something like this: