Everything is working fine for rendering components on the website, but TypeScript is showing an error when importing mdx files.
The TypeScript error message reads: Cannot find module '@/articles/good.mdx' or its corresponding type declarations.
I've come across numerous comments on Stack Overflow, but none of the solutions have resolved this issue. I even tried installing @mdx-js/mdx, but it didn't work either.
import React from "react";
import Layout from "@/components/Layout/index";
import Good from "@/articles/good.mdx"; // This line shows a TypeScript error
const index = () => {
return (
<Layout>
<Good />
</Layout>
);
};
export default index;
Package.json (some entries removed for brevity)
{
"dependencies": {
"@next/mdx": "^10.2.0",
"@types/react-transition-group": "^4.4.1",
"next": "10.1.3",
"next-seo": "^4.24.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-query": "^3.13.11",
"react-transition-group": "^4.4.1"
},
"devDependencies": {
"@mdx-js/loader": "^1.6.22",
"@types/node": "^15.0.1",
"@types/react": "^17.0.4",
"@types/webpack-env": "^1.16.0",
"autoprefixer": "^10.2.5",
"typescript": "^4.2.4"
}
}
tsconfig.json (some entries removed for brevity)
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"types": [
"node",
"webpack-env"
]
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.mdx",
],
"exclude": [
"node_modules"
]
}