SyntaxError: Unexpected token T in JSON at position 0 WHile building the website #75457
Replies: 23 comments 1 reply
-
I'm seeing this in a deployed application. Currently our leading thought is using Node 18. This stack seems to be very low level in Node itself. The error is random. All api and ANY JSON.parse calls are wrapped in try/catch. I can't reproduce it locally. |
Beta Was this translation helpful? Give feedback.
-
Same happened to us.
next app sends back 500 error, and the only recurrent log in pm2 logs is SyntaxError: Unexpected token T in JSON at position 0 |
Beta Was this translation helpful? Give feedback.
-
Same here, how you guys made this work? |
Beta Was this translation helpful? Give feedback.
-
Dunno if that can help you, but, switched the Node.js version, from 18.15, to 16.13... Give me more details on the unexpected error... |
Beta Was this translation helpful? Give feedback.
-
any suggestion to fix this with nextjs 13.x, I have tried with the latest nextjs version 13.4.2 but it still doesn't work |
Beta Was this translation helpful? Give feedback.
-
same thing is happening to me, any idea? |
Beta Was this translation helpful? Give feedback.
-
I am getting the same error. What is a stable version of NextJS to downgrade to? Edit: this one was my fault, ignore! |
Beta Was this translation helpful? Give feedback.
-
I have the same error Error: Failed to collect page data for /[id] |
Beta Was this translation helpful? Give feedback.
-
same here, SyntaxError: Unexpected token < in JSON at position 021:09:13.269 | at JSON.parse () |
Beta Was this translation helpful? Give feedback.
-
Works fine for me in dev mode but when deploying it to vercel it gives the error: SyntaxError: Unexpected token T in JSON at position 017:06:22.809 | at JSON.parse () |
Beta Was this translation helpful? Give feedback.
-
Mine is * SyntaxError: Unexpected token o in JSON at position 1* |
Beta Was this translation helpful? Give feedback.
-
I fixed this issue by using the Function method
Though I don't know if there's any security risk using the Function method, but it parses the JSON string (someVar) to an object. |
Beta Was this translation helpful? Give feedback.
-
Same error here! I can't receive a simple POST request on my endpoints without seeing this error.
|
Beta Was this translation helpful? Give feedback.
-
SyntaxError: Unexpected token < in JSON at position 015:13:37.473 | at JSON.parse () Has anyone found a solution? |
Beta Was this translation helpful? Give feedback.
-
have you got any solution? |
Beta Was this translation helpful? Give feedback.
-
Anyone have a fix for this? I can't build or deploy my SSG site at all which is a real blocker! Error seems to bomb out on making network calls during the pre-render process sst bind next dev works well More info here |
Beta Was this translation helpful? Give feedback.
-
So had time to figure out my issue this eve - for anyone else pre-rendering at build time via SSG: you need to have a dev server running as you are most likely getting internal server errors from your network calls, assuming you haven't previously deployed your backend, for those endpoints to be hit. If you are using sst like I am: It's If you encounter the infamous infinite Good luck! |
Beta Was this translation helpful? Give feedback.
-
SyntaxError: Unexpected end of JSON input01:01:40.886 | at JSON.parse () Solve nextjs13.4.12 and mongoose
if your collection is populated Mongoose ObjectId you need to find queries for populate Mongoose ObjectId |
Beta Was this translation helpful? Give feedback.
-
Removed the redundant use of JSON.stringify on the fetch response. Previously, we were attempting to stringify an already parsed JSON object, which led to the error Unexpected token o in JSON at position 0. This fix ensures that the response data is processed correctly without unnecessary conversions. |
Beta Was this translation helpful? Give feedback.
-
in my case i just catch the error from json while fetching api with const res = fetch('blablabla') return await res.json() |
Beta Was this translation helpful? Give feedback.
-
Hello guys, the issue is getting data using fetch, Every component in next js is a server component, so, just fetch data directly, instead of using fetch. This code is not working incase of vercel, ....,
fetch data directly like this
Note: |
Beta Was this translation helpful? Give feedback.
-
I had the same error and fixed it by putting the API call inside the try-catch block. This error was inside a route.ts file, and in it, I was making a fetch call that was not being handled. |
Beta Was this translation helpful? Give feedback.
-
Hi, can you elaborate on how you detected the bug and fixed it? I am running into the same error. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Verify canary release
Provide environment information
Hi , im trying to build my website and i get this error, i tried a lot of thing but nothing were helpful :
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://github.com/AnasAitzouinet/my-eco
To Reproduce
info - Collecting page data .SyntaxError: Unexpected token T in JSON at position 0
at JSON.parse ()
at parseJSONFromBytes (node:internal/deps/undici/undici:6498:19)
at successSteps (node:internal/deps/undici/undici:6472:27)
at node:internal/deps/undici/undici:1145:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Describe the Bug
im just tryin the website by next build and i get this error even thought i did alot of fixes but nothing worked
Expected Behavior
trying to build it
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Beta Was this translation helpful? Give feedback.
All reactions