Site URL: https://fmt-dp-dev.netlify.app/
I am facing a weird issue with my next.js app deployed on netlify. I say that because I don’t get this issue on Vercel, or when I build locally. This issue only occurs with my netlify app.
Anytime I try to open my app, I get
error decoding lambda response: error decoding lambda response: unexpected end of JSON input
After a lot of debugging, I realized it is coming from any page.tsx file that I have sanity loading data using const results = await client.fetch(query);
When I remove the data fetching, then the app works fine.
Again,
- I don’t see this issue when I build and run locally.
- I don’t also see this issue when I deploy to vercel.
- I only see it when I deploy to netlify which is the platform I want to use.
Also, it is worth mentioning that, this was working previously on next.js v14.x.x. I upgraded to next.js 15 and this issue started.
What confuses me is the fact that this error is caused by sanity in server components. it works fine everywhere else but netlify.
In the build logs I see the below error.
ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ReferenceError: window is not defined","reason":{"errorType":"ReferenceError","errorMessage":"window is not defined","stack":["ReferenceError: window is not defined"," at 65947 (/var/task/.next/server/chunks/9490.js:1:25520)"," at t (/var/task/.next/server/webpack-runtime.js:1:143)"," at 68517 (/var/task/.next/server/app/(quotes-layout)/quotes/[id]/page.js:1:99786)"," at t (/var/task/.next/server/webpack-runtime.js:1:143)"," at 97290 (/var/task/.next/server/app/(quotes-layout)/quotes/[id]/page.js:1:89024)"," at Function.t (/var/task/.next/server/webpack-runtime.js:1:143)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: ReferenceError: window is not defined"," at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:529:35)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
I can see that there is a "ReferenceError: window is not defined".
But I don’t know why it only occurs on netlify. I also don’t use any direct window objects in the place it is pointing to.
any help would be appreciated.