TypeError: Converting circular structure to JSON planner_1 | --> starting at object with constructor 'Socket' planner_1 | | property 'parser' -> object with constructor 'HTTPParser' planner_1 | --- property 'socket' closes the circle code example

Example: json stringify close circle

const getCircularReplacer = () => {
  const seen = new WeakSet();
  return (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) {
        return;
      }
      seen.add(value);
    }
    return value;
  };
};

JSON.stringify(circularReference, getCircularReplacer());