Reading local JSON files in Next.js
Unanswered
Mozzy posted this in #help-forum
MozzyOP
I have a number of local JSON files in my Next.js application that I need to read on the server.
When developing locally, it works, but hosted on Vercel, I receive this error:
When developing locally, it works, but hosted on Vercel, I receive this error:
[Error: ENOENT: no such file or directory, scandir '/var/task/lib/data'] {
errno: -2,
code: 'ENOENT',
syscall: 'scandir',
path: '/var/task/lib/data'
}
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
digest: '2573906759'
}4 Replies
MozzyOP
I have also tried import(), which leads to the same error.
Wne I had similar issue, I had to remove dynamic import and top level import it so that vercel knew to bundle the file (but theis was dynamic import folder JS files)
MozzyOP
Thanks
I went another route though and ditched the json file idea