Next.js Discord

Discord Forum

My NextJS site In local works fine, but when I deploy the site, Vercel don't upload my markdown file

Answered
Sage Thrasher posted this in #help-forum
Open in Discord
Sage ThrasherOP
I have a problem with Vercel deploying my NextJS site. In local everything works fine, but when I deploy the site, Vercel don't upload my markdown files and then the site can't render them because it can't find them.

My .md files are in a folder named "posts" on the root. I have tried to move the folder inside the app directory but Vercel still doesn't upload the files when I do the deploy.

My code:
import fs from "fs";
import matter from "gray-matter";

const getPostContent = (slug: string) => {
const folder = "posts/";
const file = ${folder}${slug}.md;

try {
const content = fs.readFileSync(file, "utf8");
const matterResult = matter(content);
return matterResult;
} catch (error) {
const notFoundContent = "Article not found";
const notFoundMatterResult = matter(notFoundContent);
return notFoundMatterResult;
}
};

In local, all the articles are rendered as expected, but when I try the site on Vercel directly goes to the catch block.

Hope somebody can help me, thank you!
Answered by linesofcode
path.resolve(process.cwd(), “docs/foo.md”)
View full answer

5 Replies

Hey
Build the file path using process.cwd
path.resolve(process.cwd(), “docs/foo.md”)
Answer
@Sage Thrasher
@linesofcode Hey
Sage ThrasherOP
Thankss!!! It works!!