Next.js Discord

Discord Forum

TypeError: Failed to Fetch

Unanswered
Broken Nokia posted this in #help-forum
Open in Discord
cartTotal is of type CartItem[] and total is of type number

What could be causing this error?

23 Replies

@Broken Nokia `cartTotal` is of type `CartItem[]` and `total` is of type `number` What could be causing this error?
can you show the console.log? And also show the network request please. And also show the result of the network request please
i hope this is what you're asking
i even tried dsabling cache
@Broken Nokia Click to see attachment
it looks like your custom backend server (on port :5000) does not have any CORS set. So either set the correct CORS (details what you need to set in error message) or host your backend on :3000 (the next app) as well
i'm trying to get cors setup on my express server at the moment
@Broken Nokia i'm trying to get cors setup on my express server at the moment
do u need help in that or u good?
@gin do u need help in that or u good?
i am getting a "couldn't find declaration for cors" error when i try to import it (i'm using ES modules and not common js in my package.json)
@Broken Nokia Click to see attachment
do u have the express types installed?
npm i @types/express
i do
show me your tsconfig
and install that aswell @types/cors
npm install --save @types/cors
@gin npm install --save @types/cors
this seems to have fixed it, thank you
👍
just a question, does this cors issue also get flagged as a type error?

or was the root cause something else and not cors?
setup cors and try if your fetch works
the fetch did happen but there's a server error from my backend, likely a mismatch of schema, i'll see if that fixes things