我试图在使用.js的反应中将一个gatsby-plugin-mdx文件加载到标记文件中。但是,我遇到了一个导入错误,它显示为警告,如下所示:
警告./.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: { '}': '{' }
escapeEntities: {},
}
},
]
}
},
{
resolve: "gatsby-plugin-page-creator",
options: {
path: `${__dirname}/src/`,
},
},
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.mdx`, `.md`],
},
},
],
}我认为我的查询/段塞用法很好,因为站点和帖子在尝试实现mdx之前(和之后)都是可操作的。通过观察gatsby-plugin-mdx文档,我试图使用gatsbyRemarkPlugins封装其他插件,但这并没有改变警告。更确切地说,你认为我的mdx使用会有什么问题吗?
发布于 2022-07-22 00:02:55
这个问题是以我的方式进口的。我只是改变了
import { Test2 } from "../pages/test2"
<Test2 />至
import Test2 from "../pages/test2"
<Test2 />as并不像我想象的那样是一个命名的导出/导入。相反,Test2.js使用默认的导出,它不需要用大括号包装。
https://stackoverflow.com/questions/68764478
复制相似问题