-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[Bug]: Type errors for generated type files that correspond to .mdx
route files
#12362
Comments
Appending type Module = typeof import("../this-is-an-mdx-file.mdx") |
Creating a export {} These files should be colocated next to the corresponding |
Note that this isn't a React Router issue. Can you try two things?
declare module '*.mdx' {
let MDXComponent: (props: any) => JSX.Element;
export default MDXComponent;
} |
Having this same issue in a project using Since the import generated by the react-router types doesn't include the // .react-router/types/app/routes/+types/_articles.beyond-wave-echo-cave.ts
type Module = typeof import("../_articles.beyond-wave-echo-cave"); // this needs an mdx extension
For now I am doing this since I don't have many |
It is: React Router generates files with invalid imports. The corresponding
This doesn’t fix the issue. The issue is due to missing file extensions. The TypeScript compiler allows for some implicit file extensions ( |
Ah, I didn't catch this was for typegen. I'll let others respond to that since it's not my thing. |
There are two main ways to handle MDX:
It's always been conceptually cleaner to treat MDX as content, but in practice this usually meant implementing and maintaining your own (cached) unify/remark/rehype pipeline. Its tricky to set up correctly and there are a bunch of footguns around how components/assets referenced by those MDX files get treated. So for a while, we explored MDX as routes (for example, here's a demo I built https://github.com/pcattori/remix-blog-mdx). The nice thing about this approach is that all bundling/transforms are done via Vite. So that means you can use an out-of-the-box solution like By the way, allowing non-JS/TS files (like MDX) to be routes adds tons of complexity that requires us to run a "child compiler" under-the-hood, which has been causing all sorts of issues. I'm actively working on a framework-agnostic way to model content like MDX similar to how Astro does it. Hoping to show this off soon. |
I understand that it looked sketch in the file based routing but the layout mdxlayout.tsx and route post.tsx in the routes.ts was pretty intuitive. But i don't think you can selectively apply layouts for mixed tsx and mdx routes at the same parent url with the file based routing so I can see a reason to do something else. It would be nice to retain a solution to grab all the headings and titles from the content collection to dynamically make cards/links and table of contents. The way I got it working was pretty hacky with the rehype plugin and vite.glob so a better solution would be cool. I'll be happy with any robust solution. Thanks for working on it! |
I ran into this same issue, and took a stab at fixing it in #12453 |
What version of React Router are you using?
7
Steps to Reproduce
.mdx
file(s) in your routes foldernpm run typecheck
.mdx
routesExpected Behavior
No type errors
Actual Behavior
The generated type files contain a line like
The type error is as follows:
The text was updated successfully, but these errors were encountered: