Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

TypeError: response.json is not a function — what did fetch return?

Illustration without a description Illustration without a description

The value called response does not have a callable json() method. It may be an Axios result, a plain object returned by a helper, or a mock. Look at the value that reached the failing line before changing how the endpoint responds.

 

Follow the request helper to its return statement. Use json() once on a Fetch Response. With Axios, inspect response.data, and with a helper that already parses the body, use the returned data directly. If a test mock is involved, make it match the contract that the caller expects.

 

If several callers use the same request helper, decide whether it returns a Response or the parsed payload and make the tests use that shape. A mock that already returns JSON can hide a second read in application code.

 

const response = await fetch('/api/info'); if (!(response instanceof Response)) throw new TypeError('Expected Fetch Response'); const data = await response.json();

 

Log the returned value and its constructor at the call site, then check whether the helper already parsed the body.