Program in server actions cannot bundle the correct static file

const csvFilePath = path.join(process.cwd(), 'prices.csv');

export const priceTable = await readCSV(csvFilePath)

When I use process.cwd() to get a CSV file, if this part of code is in server actions, the bundler will not correctly bundle the target CSV file. In Vercel it will raise a file not found runtime error.

If this code in the normal page router api route or app router API route, it works fine.

I assume it is some issue of vercel nft https://github.com/vercel/nft . Anyone has some idea?

Hi @bxclib2, welcome to the Vercel Community!

Thanks for reaching out in the community. Let me try and recreate this issue.

Hi @bxclib2, I created this sample repository to see what could be going wrong and I was able to recreate the issue: https://sample-latest-nextjs.vercel.app/

Can you confirm this is the issue you are referring to?

Hi @bxclib2, after digging in deeper and help from our team. I was able to solve this issue by using the outputFileTracingIncludes option to explicitly include the data directory:

import type { NextConfig } from "next";
 
const nextConfig: NextConfig = {
  /* config options here */
  outputFileTracingIncludes: {
    '/': ['./src/data/*']
  }
};

This should solve the issue for you as well.

hi, yes, it seems this is the issue i am referring to. Let me try your solution.

2 Likes

hi thanks this solved my problem. but it would be better to make this happen automatically if possible.

thank you very much

2 Likes

Hi @bxclib2, we’ve merged a fix for this issue. :tada: