I am tryiing to make next js 13 mdx blog website with the latest app router I am getting this error => Module not found: Can't resolve 'fs' In next js 12 and pages directory its working but in the latest app router it's not working
this is my code,
"use client"
import Head from 'next/head';
import BlogSidebar from '../../components/blog/sidebar';
import Pagination from '../../components/blog/pagination';
import fs from 'fs';
import matter from 'gray-matter';
import { join } from 'path';
import { useRouter } from 'next/router'
export async function getStaticProps() {
const blogsDirectory = join(process.cwd(), '_blog');
const files = fs.readdirSync(blogsDirectory);
let posts = files.map((fileName) => {
const slug = fileName.replace(/\.md$/, '');
const fullPath = join(blogsDirectory, `${slug}.md`);
const readFile = fs.readFileSync(fullPath, 'utf8');
const { data: frontmatter } = matter(readFile);
return {
slug,
frontmatter,
};
});
posts = posts.sort((job1, job2) => (job1.frontmatter.date > job2.frontmatter.date ? -1 : 1));
return {
props: {
posts,
},
};
}
const page = ({ posts }) => {
console.log(posts, "posts");