title: NextJS: TypeError: Cannot read property 'json' of undefined
body: <p>I've this code into pages folder on my NextJS environment. It gets data calling an external API Rest, and it's working because the <code>console.log(response);</code> line show me by console the Json API response. The problem I've is that I get this error in browser:</p>
  <p><strong>TypeError: Cannot read property 'json' of undefined</strong></p>
  <p>Corresponding with this line code:</p>
  <p><code>const data = await res.json();</code></p>
  <p>This is the complete file with the code:</p>
  <pre><code>import React from &quot;react&quot;;
  import fetch from &quot;node-fetch&quot;;
  
  const getFetch = async (invoicesUrl, params) =&gt; {
    fetch(invoicesUrl, params)
      .then((response) =&gt; {
        return response.json();
      })
      .then((response) =&gt; {
        console.log(response);
      })
      .catch((err) =&gt; {
        console.log(err);
      });
  };
  
  export const getServerSideProps = async () =&gt; {
    const invoicesUrl = &quot;https://192.168.1.38/accounts/123456&quot;;
    const params = {
      method: &quot;get&quot;,
      headers: {
        Accept: &quot;application/json&quot;,
        &quot;Content-Type&quot;: &quot;application/json&quot;,
      },
    };
    const res = await getFetch(invoicesUrl, params);
    const data = await res.json();
    console.log(&quot;Data Json: &quot;, data);
  
    return { props: { data } };
  };
  
  </code></pre>
  <p>This is the Json API response that I see by console:</p>
  <pre><code>{
    account: [
      {
        id: '7051321',
        type: 'probe',
        status: 'open',
        newAccount: [Object],
        lastDate: '2020-07-04',
        taxExcluded: [Object],
        totalRecover: [Object],
        documentLinks: []
      },
    ]
  }
  </code></pre>
  <p>Any idea how can I solve it?
  Thanks in advance.</p>
  <p><strong>UPDATE</strong>
  Here the code working good:</p>
  <pre><code>import React from &quot;react&quot;;
  import fetch from &quot;node-fetch&quot;;
  
  const getFetch = async (invoicesUrl, params) =&gt; {
     return fetch(invoicesUrl, params);
  };
  
  export const getServerSideProps = async () =&gt; {
    const invoicesUrl = &quot;https://192.168.1.38/accounts/123456&quot;;
    const params = {
      method: &quot;get&quot;,
      headers: {
        Accept: &quot;application/json&quot;,
        &quot;Content-Type&quot;: &quot;application/json&quot;,
      },
    };
    try {
      const res = await getFetch(invoicesUrl, params);
      const data = await res.json();
      console.log(&quot;Data JSON: &quot;, data);
      return { props: { data } };
    } catch (error) {
      console.log(&quot;Data ERROR: &quot;, error);
    }
  };
  
  </code></pre>