I have pretty much followed the tutorial here https://magrippis.com/blog/2020/how-to-setup-MDX-in-Nextjs, using this Next.js plugin https://github.com/hashicorp/next-mdx-enhanced, however when I try to add a template file with a .tsx or .ts extension or reference another component within the template file that is a .tsx or .ts I get an error saying "Module not found". I can use other .tsx files just not within the templates, for example, I can use it for pages or components not references within the templates.
next.config.js file:
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 file (Not sure if this matters):
{
"presets": ["next/babel"],
"plugins": ["import-glob-array"]
}