0

我正在尝试使用 .js 将 .js 文件加载到 React 中的我的 markdown 文件中gatsby-plugin-mdx。但是,我遇到了一个导入错误,它显示为 WARN,如下所示:

警告 ./.cache/caches/gatsby-plugin-mdx/mdx-scopes-dir/7cd2ab5f9fe4b662b5bb93052ee9e f2c.js 尝试导入错误:“Test2”未从“../../../../src/”导出pages/test2'
(导入为'Test2')。

查看缓存,它似乎足够良性:

import { Test2 } from "../../../../src/pages/test2";
import * as React from 'react';
export default {
  Test2,
  React
};

导入的内容似乎是任意的,并且警告将是相同的(并且内容不会加载)。例如,我使用了一个简单的导出默认函数返回一个 h1 标记来进行实验。

我的 .md 文件相当简单:

# Testing 1 
top
import { Test2 } from "../pages/test2"
<Test2 />
bottom

我怀疑这是一个配置问题,但我还没有在我的 gatsby-config.js 中解决它,目前如下:

module.exports = {
  siteMetadata: {
    title: 'Marco Sousa Blog',
    author: 'Marco Sousa'
  },

  plugins: [
    'gatsby-plugin-dark-mode',
    'gatsby-plugin-react-helmet',
    'gatsby-plugin-sass',
    'gatsby-plugin-sharp',
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        name:'src',
        path: `${__dirname}/src/`
      }
    },
    {
      resolve: 'gatsby-transformer-remark',
      options: {
        plugins: [
          'gatsby-remark-relative-images',
          {
            resolve: 'gatsby-remark-images',
            options: {
              maxWidth: 750,
              linkImagesToOriginal: false
            }
          },
          {
            resolve: `gatsby-remark-katex`,
            options: {
              // Add any KaTeX options from https://github.com/KaTeX/KaTeX/blob/master/docs/options.md here
              //strict: `ignore`,
             
            }
          }, 
          {
            resolve: `gatsby-remark-prismjs`,
            options: {
              classPrefix: "language-",
              inlineCodeMarker: null,
              aliases: {},
              showLineNumbers: true,
              noInlineHighlight: false,

              languageExtensions: [ 
                {
                  language: "superscript",
                  extend: "javascript",
                  definition: {
                    superscript_types: /(SuperType)/,
                  },
                  insertBefore: {
                    function: {
                      superscript_keywords: /(superif|superelse)/,
                    },
                  },
              },
            ],
            prompt: {
              user: "root",
              host: "localhost",
              global: false,
            },
            // By default the HTML entities <>&'" are escaped.
            // Add additional HTML escapes by providing a mapping
            // of HTML entities and their escape value IE: { '}': '&#123;' }
            escapeEntities: {},
            }
          },
        ]
      }
    },
    {
      resolve: "gatsby-plugin-page-creator",
      options: {
        path: `${__dirname}/src/`,
      },
    },
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        extensions: [`.mdx`, `.md`],
      },
    }, 
  ],
}

我认为我的查询/slug 使用很好,因为站点和帖子在尝试实施 mdx 之前(和之后)是可操作的。观察gatsby-plugin-mdx 文档,我试图用它gatsbyRemarkPlugins来封装其他插件,但这并没有改变警告。更确切地说,您认为我的 mdx 使用可能是什么问题?

4

0 回答 0