gouravkhator/stran

[OLD_BUG]: TypeError: Converting circular structure to JSON

gouravkhator opened this issue · 1 comments

Note: This was an old bug. It is been fixed, but just to keep here for archival purposes.

Describe the bug

When createIPFSNodeIfNA method in the /server/middlewares/ipfs.middleware.js is being called, req.session.ipfsNode or req.cookies.ipfsNode got assigned to the IPFS node created.

When we call res.send or res.end or res.sendStatus etc. methods, it internally does JSON.stringify(res.session), and req.session.ipfsNode or req.cookies.ipfsNode cannot be stringified, as the ipfsNode created was a circular structure.

To Reproduce

Steps to reproduce the behavior:

  1. Make sure go-ipfs is not installed in your system
  2. Then run the server by 'nodemon server.js' and make any type of request to <server-url>/ipfs/<data-cid>

Environment

  • NodeJS v16.13.0

Error Stack Trace

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Libp2p'
|     property '_options' -> object with constructor 'Object'
|     property 'modules' -> object with constructor 'Object'
|     ...
|     property '_wan' -> object with constructor 'KadDHT'
--- property '_libp2p' closes the circle
at JSON.stringify (<anonymous>)

Resolution

Install go-ipfs on your system and run the local ipfs node daemon.

This issue was raised for archival purpose. And it has been solved by the given resolution method.