I'm currently in the process of setting up a blog section on my personal website. However, I've encountered an error that's preventing me from accessing a specific blog post:
(Vercel logs)
Error: ENOENT: no such file or directory, open '/var/task/src/content/hello.mdx'
at Object.openSync (node:fs:601:3)
at Object.readFileSync (node:fs:469:35)
at PostPage (/var/task/.next/server/app/posts/[slug]/page.js:381:45)
at S (/var/task/.next/server/chunks/789.js:6503:13)
at eb (/var/task/.next/server/chunks/789.js:6618:21)
at Array.toJSON (/var/task/.next/server/chunks/789.js:6422:20)
at stringify (<anonymous>)
at pb (/var/task/.next/server/chunks/789.js:6829:9)
at mb (/var/task/.next/server/chunks/789.js:6728:29)
at Timeout._onTimeout (/var/task/.next/server/chunks/789.js:6553:16) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/var/task/src/content/hello.mdx'
}
Upon attempting to view a blog post on my portfolio site, the following error message pops up:
Application error: a server-side exception has occurred (see the server logs for more information). Digest: 2113801254
This is the current structure of my project directory:
my-app/
└── src/
├── app/
│ ├── posts/
│ │ ├── page.js
│ │ └── [slug]/
│ │ └── page.js or PostPage
│ └── page.js
├── layout.js
├── page.js
├── components
├── content/
│ └── hello.mdx
└── fonts
The error indicates that there's an issue with the PostPage
file. Here's the code snippet causing the problem:
export default function PostPage({ params }) {
const post = fs.readFileSync(
path.join(__dirname, "../../../../../src/content/" + params.slug + ".mdx"),
"utf-8"
);
const { data: frontmatter, content } = matter(post);
const blog = DOMPurify.sanitize(
marked.parse(content, { mangle: false, headerIds: false })
);
.....
//returns jsx with markdown content
}
I've attempted adjusting the path in the readFileSync()
function without success in production. It does work in local dev mode. Any assistance would be greatly appreciated.
Just a beginner in programming and navigating tools like Next.js and Vercel. Thank you!