【发布时间】:2021-05-18 00:50:14
【问题描述】:
我已经非常关注https://magrippis.com/blog/2020/how-to-setup-MDX-in-Nextjs 此处的教程,使用此 Next.js 插件 https://github.com/hashicorp/next-mdx-enhanced,但是当我尝试添加扩展名为 .tsx 或 .ts 的模板文件或引用模板文件中的另一个组件时那是 .tsx 或 .ts 我收到一条错误消息“找不到模块”。我可以使用不在模板中的其他 .tsx 文件,例如,我可以将它用于模板中没有引用的页面或组件。
next.config.js 文件:
const withPlugins = require('next-compose-plugins');
const rehypePrism = require('@mapbox/rehype-prism');
const mdx = require('next-mdx-enhanced')({
defaultLayout: true,
fileExtensions: ['mdx', 'md'],
rehypePlugins: [rehypePrism],
});
// you may tweak other base Next options in this object
// we are using it to tell Next to also handle .md and .mdx files
const nextConfig = {
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'mdx', 'md'],
future: {
webpack5: false,
},
};
module.exports = withPlugins(
[
mdx,
// you may add more plugins, and their configs, to this array
],
nextConfig
)
.babelrc 文件(不确定这是否重要):
{
"presets": ["next/babel"],
"plugins": ["import-glob-array"]
}
【问题讨论】:
标签: next.js