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

Unable to import toc and metadata from .mdx when unifiedjs.vscode-mdx in on at VS Code #4193

Open
MOZGIII opened this issue Feb 11, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@MOZGIII
Copy link

MOZGIII commented Feb 11, 2025

Describe the bug A clear and concise description of what the bug is.

import Content, { metadata, toc } from "./content.mdx";

shows errors:

Module '"./content.mdx"' has no exported member 'metadata'. Did you mean to use 'import metadata from "./content.mdx"' instead?
Module '"./content.mdx"' has no exported member 'toc'. Did you mean to use 'import toc from "./content.mdx"' instead?

However, when I add the following mdx.d.ts:

declare module "*.mdx" {
  import type { Heading, NextraMetadata } from "nextra";

  let MDXComponent: (props) => JSX.Element;
  export default MDXComponent;

  export const metadata: NextraMetadata;
  export const toc: Heading[];
}

It starts working file for tsc.

In the VS Code though, the unifiedjs.vscode-mdx provides a language server, which does some magic code injections into the evaluation context at which it itself works (see here) - and long shorty short it breaks the types.

Image

This is some hellish interaction, but it should be correctable by passing the right settings to the language server - in particular, the plugins we use to generate those toc and metadata parameters.

To Reproduce Steps to reproduce the behavior:

  1. Install VS Code.
  2. Install unifiedjs.vscode-mdx extension from the VS Code marketplace.
  3. Make some dummy content.mdx file.
  4. Make some page.tsx file with (app router) and try importing metadata and toc from that content.mdx like the above.
  5. Observer the error in the editor and in tsc.
  6. Bring in the mdx.d.ts from above, see the error gone from the tsc but no the editor.

Expected behavior A clear and concise description of what you expected to
happen.

Well, believe it or not, I expected it to just work.

Screenshots If applicable, add screenshots to help explain your problem.

See above.

Desktop (please complete the following information):

potato

Smartphone (please complete the following information):

tomato

Additional context Add any other context about the problem here.

I'm so mad. Sorry if this came out rude.

@MOZGIII MOZGIII added the bug Something isn't working label Feb 11, 2025
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

No branches or pull requests

1 participant