reactjstypescriptreact-typescript

React - framework error Cannot read properties of undefined (reading 'split')


I've been trying to figure out the following error when running a react project I'm working on.

"Cannot read properties of undefined (reading 'split')"

The error appears when adding a async fetch to grab some data from an API.

Recently just adding the following code to allow cross origin data fetching causes the issue with no fetch. Not fetching data or anything. It's rather strange.

const agent = new Agent({
    connect: {
      rejectUnauthorized: false
    }
  });
  
setGlobalDispatcher(agent);

I'll continue to try and lock it down and append any information here as I can see it's a bit vague.

Added a screen shot of the Error.

I understand the vote down I do, this issue is really hard to describe and I might be appealing to such a small group people who might have seen this issue it might never catch their eye. Thanks to anyone who read this.

enter image description here


Solution

  • You have a dependency that is not meant to run in the browser: undici

    An HTTP/1.1 client, written from scratch for Node.js.

    The line node.split('.') therefore errors, because there is no node object in the browser. So something with your setup doesn't make sense.