custom-website-series
custom-website-series copied to clipboard
Deployment fails with invalid json response body fetcherror
Everything works great on local. But, deployment doesn't seem to work. First time I deployed the error was the following
node:internal/process/promises:279 6:27:50 PM: triggerUncaughtException(err, true /* fromPromise */); 6:27:50 PM: ^ 6:27:50 PM: FetchError: invalid json response body at https://server/api/studies reason: Unexpected token < in JSON at position 0 6:27:50 PM: at /opt/build/repo/node_modules/node-fetch/lib/index.js:272:32 6:27:50 PM: at processTicksAndRejections (node:internal/process/task_queues:96:5) 6:27:50 PM: at async getStaticPaths (/opt/build/repo/.next/server/pages/studies/[page].js:25:23) 6:27:50 PM: at async buildStaticPaths (/opt/build/repo/node_modules/next/dist/build/utils.js:16:80) 6:27:50 PM: at async /opt/build/repo/node_modules/next/dist/build/utils.js:26:622 6:27:50 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584) { 6:27:50 PM: type: 'invalid-json' 6:27:50 PM: }
Second time, it was the following
7:26:09 PM: node:internal/process/promises:279 7:26:09 PM: triggerUncaughtException(err, true /* fromPromise */); 7:26:09 PM: ^ 7:26:09 PM: FetchError: invalid json response body at https://server/api/studies?limit=100 reason: Unexpected token < in JSON at position 0 7:26:09 PM: at /opt/build/repo/node_modules/node-fetch/lib/index.js:272:32 7:26:09 PM: at processTicksAndRejections (node:internal/process/task_queues:96:5) 7:26:09 PM: at async getStaticPaths (/opt/build/repo/.next/server/pages/study/[study].js:271:21) 7:26:09 PM: at async buildStaticPaths (/opt/build/repo/node_modules/next/dist/build/utils.js:16:80) 7:26:09 PM: at async /opt/build/repo/node_modules/next/dist/build/utils.js:26:622 7:26:09 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584) { 7:26:09 PM: type: 'invalid-json' 7:26:09 PM: }
Third time,
7:31:54 PM: node:internal/process/promises:279 7:31:54 PM: triggerUncaughtException(err, true /* fromPromise */); 7:31:54 PM: ^ 7:31:54 PM: FetchError: invalid json response body at https://server/api/pages?limit=100 reason: Unexpected token < in JSON at position 0 7:31:54 PM: at /opt/build/repo/node_modules/node-fetch/lib/index.js:272:32 7:31:54 PM: at processTicksAndRejections (node:internal/process/task_queues:96:5) 7:31:54 PM: at async getStaticPaths (/opt/build/repo/.next/server/chunks/488.js:484:20) 7:31:54 PM: at async buildStaticPaths (/opt/build/repo/node_modules/next/dist/build/utils.js:16:80) 7:31:54 PM: at async /opt/build/repo/node_modules/next/dist/build/utils.js:26:622 7:31:54 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584) { 7:31:54 PM: type: 'invalid-json' 7:31:54 PM: }
I tried converting studiesReq to text instead and logging it to the console. Here's what I found
6:56:24 PM: info - Checking validity of types...
6:56:32 PM: Failed to compile.
6:56:32 PM:
6:56:32 PM: ./pages/studies/[page].tsx:11:14
6:56:32 PM: Type error: Type '() => Promise${process.env.NEXT_PUBLIC_SERVER_URL}/api/studies);
6:56:32 PM: 13 | // const studiesData = await studiesReq.json();
6:56:32 PM: 14 | const studiesData = await studiesReq.text();
I tried looking up some solutions and it's recommended that await be used to resolve the promise before the assignment. But, it's already what's being done. I hit a dead end. Could you please help?