0

I am trying to create some dynamic pages from mdx in gatsby, using below code

import { compileMDX } from 'gatsby-plugin-mdx';
import remarkGfm from 'remark-gfm';

const mdxContent = await compileMDX(
    { absolutePath, source: content.toString() },
    {
        outputFormat: 'function-body',
        jsxRuntime: 'automatic',
        jsx: false,
        useDynamicImport: true,
        remarkPlugins: [remarkGfm]
    }, cache, reporter
)

But it doesn't seem to be working, I read at https://github.com/gatsbyjs/gatsby/discussions/37069 that gatsby compies gatsby-node.ts to CommonJs module. Getting below error -

Failed to import compiled file ".cache/compiled/gatsby-node.js" after retry, attempting
another retry (#2 of 5) - "require() of ES Module node_modules/remark-gfm/index.js from .cache/compiled/gatsby-config.js not supported.
Instead change the require of index.js in .cache/compiled/gatsby-config.js to a dynamic import()
 which is available in all CommonJS modules."

I tried changing to dynamic import but still getting the same error

const remarkGfm = await import('remark-gfm')
const mdxContent = await compileMDX(
    { absolutePath, source: content.toString() },
    {
        outputFormat: 'function-body',
        jsxRuntime: 'automatic',
        jsx: false,
        useDynamicImport: true,
        remarkPlugins: [remarkGfm.default]// tried [remarkGfm] as well
    }, cache, reporter
)

I feel like something else is wrong and its possibly misleading error. Any help on this would be highly appreciated thanks.

4
  • An error message is not code and shouldn't use code formatting... Commented Aug 16, 2024 at 18:49
  • Thanks for the comment, I feel it helpful to keep the error more readable and clear. Code formatting helps doing that. Commented Aug 16, 2024 at 18:59
  • Can you post the file type used? Commented Sep 6, 2024 at 14:24
  • I was using typescript, .ts files. Commented Sep 17, 2024 at 19:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.