Next.js Discord

Discord Forum

File not found in production

Answered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
I have the following code here where it reads from a .md file and renders it. The file is perfectly found in development but when I push to production the file path is changed. What should I do?

code:
export default async function Terms() {
  const text = await fs.readFile(`${process.cwd()}/src/static/terms.md`);

  const content = await unified()
    .use(remarkParse)
    .use(remarkHtml)
    .process(text);

  return (
    <div
      className="prose w-full max-w-6xl"
      dangerouslySetInnerHTML={{ __html: String(content.value) }}
    ></div>
  );
}

8 Replies

@Jboncz When you say push to production do you mean running it as a service or hosted? Depending on how you start the service the 'base' directory in which its started may change, try using a static route to the resource.
Spectacled CaimanOP
Yeah I hosted on vercel is what I meant. By static do you me mean like example.com/static/terms.md or do you mean somethign else. Because then that means I'd have to move it to the public folder
Didnt mean that, sorry. Im not familiar with vercel enough to help troubleshoot.... We self host, so not sure.
Spectacled CaimanOP
ah okay, thanks
Answer
This may help?
You have to tell the bundler to include the files on build it seems.
Spectacled CaimanOP
ah okay thank you very much this is very helpful! 💙