i have hosted a site https://harshdewanganportfolio.netlify.app/, and i am using some apis to fetch data from json files stored localy in next.js folder named “data”.In deployment apis work fine but on production on netfliy.com it gives error
as shown in image
in netfliy function logs i am getting this
{“errorType”:“SyntaxError”,“errorMessage”:“Unexpected token u in JSON at position 0”,“stack”:[“SyntaxError: Unexpected token u in JSON at position 0”," at JSON.parse ()“,” at ReadFileContext.callback (/var/task/.next/server/pages/api/getskills.js:29:39)“,” at FSReqCallback.readFileAfterOpen [as oncomplete] (node:fs:319:13)"]}
this is my folder structure and the getskills api file
.I don’t what is the problem like may i mention the path of data/allskills.json wrongly
your help will be appreciated
@Harsh-bhai I can’t answer from the specific perspective of Next.js
and whatever additional handling Netlify has implemented for that, (as I don’t use it), but if the api routes are created as functions, my guess is that the json
files simply aren’t being included in the bundle.
You can read a little about it here:
And more here under included_files
:
Investigating that angle may help you solve it.
I wonder why not to simply import the JSON files instead of reading them from file system? Any specific use case @Harsh-bhai?