Coder Social home page Coder Social logo

custom-website-series's Issues

Upgrade to nextjs 13

I took this project last year and modified it for my specific use, now i wanted to upgrade it to nextjs 13 and latest payload but am getting errors, was wondering if the repo can be updated. its a nightmare for me.

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' is not assignable to type 'GetStaticPaths'.
6:56:32 PM: Type 'Promise' is not assignable to type 'Promise<GetStaticPathsResult>'.
6:56:32 PM: Type 'void' is not assignable to type 'GetStaticPathsResult'.
6:56:32 PM: 9 | };
6:56:32 PM: 10 |
6:56:32 PM: > 11 | export const getStaticPaths: GetStaticPaths = async () => {
6:56:32 PM: | ^
6:56:32 PM: 12 | const studiesReq = await fetch(${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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.