500 Internal Server Error when getting a markdown file. NexjJS 14

Works on local but not when I push: https://smartmontag.netlify.app/news/hello

I am using nextjs 14, I have a [slug] with fs to get a markdown files from a separate folder and then render it.

This is my structure:

  • news
    • hello.md
    • other md files
  • app
    • news
      • [slug]

Any suggestions how to debug and where to looks? Is there a log on netlify? I found one but no errors there =(

Here is how I get the files in “news” folder:

import fs from "fs";
import matter from "gray-matter";
import { join } from "path";

const postsDirectory = join(process.cwd(), "news");

export function getPostSlugs() {
  return fs.readdirSync(postsDirectory);

export function getPostBySlug(slug) {
  const realSlug = slug.replace(/\.md$/, "");
  const fullPath = join(postsDirectory, `${realSlug}.md`);
  const fileContents = fs.readFileSync(fullPath, "utf8");
  const { data, content } = matter(fileContents);

  return { ...data, slug: realSlug, content };

export function getAllPosts() {
  const slugs = getPostSlugs();
  const posts = slugs
    .map((slug) => getPostBySlug(slug))
    // sort posts by date in descending order
    .sort((post1, post2) => (post1.date > post2.date ? -1 : 1));
  return posts;

How to Include Files in Netlify Serverless Functions