Unable to fetch excel file in production in nextjs

Viewed 389

I have an excel file named Words.xlsx in public directory. Initially, during development mode, setting file path to /public/Words.xlsx worked fine but it failed in production mode saying that it can't read file path. Then, I read this and changed path to/Words.xlsx but I am still receiving the same error(below) in my function logs of vercel.

[Error: ENOENT: no such file or directory, open '/Words.xlsx'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Words.xlsx'
}
ENOENT: no such file or directory, open '/Words.xlsx'

Further, I am using this npm package to read excel file. Below is the code of how I use it:

const res1Sheet = await readXlsxFile('/Words.xlsx', { sheet: 1 });

How do I solve this?

2 Answers

Checking documentation, found this. Hopefully it might help someone who comes here one day. Note: Only assets that are in the public directory at build time will be served by Next.js. Files added at runtime won't be available. We recommend using a third party service like AWS S3 for persistent file storage.

Related