qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] frontmatter named import

Open JMRBDev opened this issue 1 year ago • 2 comments

Which component is affected?

Qwik Rollup / Vite plugin

Describe the bug

I originally wanted to get the frontmatter from an imported .mdx file. useDocumentHead() method wouldn't be suitable for this as I intend to access frontmatter from a completely different page.

As suggested by QwikAI ⬇️:

import Post, { frontmatter } from "../../../../content/blog/test-post.mdx";

This solution is working right now. However, Typescript throws an error as you can see on the Reproduction step.

I am able to temporarily fix this by adding this module definition on a custom.d.ts file at my project's root:

declare module "*.mdx" {
  export const frontmatter: { title: string };
}

I have seen there is no official support for MDX inside JSX (this is different than the MDX routing thing). Is this going to be a thing anytime soon?

Reproduction

https://stackblitz.com/edit/qwik-starter-y7ukrj?file=src/routes/index.tsx

Steps to reproduce

Import {frontmatter} from a .mdx file:

import Post, { frontmatter } from "../../../../content/blog/test-post.mdx";

image (Error says: The module ".mdx" does not have any "frontmatter" member exported. Did you mean to use "import frontmatter from ".mdx"" instead?)

This has been suggested by QwikAI, even though this particular case I believe is not still covered by the docs itself. But it technically works! I can access frontmatter by named-importing it from the mdx file: image

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M1
    Memory: 46.50 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
Binaries:
    Node: 18.15.0 - ~/.volta/tools/image/node/18.15.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 9.5.0 - ~/.volta/tools/image/node/18.15.0/bin/npm
    Watchman: 2023.04.17.00 - /opt/homebrew/bin/watchman
Browsers:
    Chrome: 113.0.5672.92
    Safari: 16.4
npmPackages:
    @builder.io/qwik: ^1.1.1 => 1.1.1 
    @builder.io/qwik-city: ^1.1.1 => 1.1.1 
    undici: 5.22.0 => 5.22.0 
    vite: 4.3.5 => 4.3.5

Additional Information

No response

JMRBDev avatar May 12 '23 11:05 JMRBDev

Would u be up to create a PR? updating the types?

manucorporat avatar May 12 '23 18:05 manucorporat