Reputation: 119
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?
Upvotes: 2
Views: 1672
Reputation: 1
give full path such as public/Words.xlsx Refer this documentation: https://docs.sheetjs.com/docs/demos/content#nextjs
you can use this sysntax: const res1Sheet = await readXlsxFile('public/Words.xlsx', { sheet: 1 });
Upvotes: 0
Reputation: 11
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.
Upvotes: 1