Next.js Discord

Discord Forum

client fetch json response Type Error

Answered
Yellow-breasted Bunting posted this in #help-forum
Open in Discord
Yellow-breasted BuntingOP
made a new repo today, trying to fetch from a route handler, but I get a type error on calling .json on the response.

  useEffect(() => {
    fetch('/api/get')
      .then((res) => res.json()) // type error
      .then((data) => {
        const result = apiResponseSchema.parse(data)
        setData(result)
        setLoading(false)
      })
  }, [])


type error:
Property 'json' does not exist on type 'Response'. Did you mean to access the static member 'Response.json' instead?


My ts config hasnt been changed...

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}


any ideas, driving me a bit mad..
Answered by Yellow-breasted Bunting
there was @types/web dependency in my package.json that got installed, must have made a global change... uninstalled it fixed the problem
View full answer

1 Reply

Yellow-breasted BuntingOP
there was @types/web dependency in my package.json that got installed, must have made a global change... uninstalled it fixed the problem
Answer