question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting circular structure to JSON

See original GitHub issue

Getting the below error since may be after the recent feathers lib update. The error appears randomly at the end of different services. Error goes away on disabling events (as of now app wide) using context.event = null;

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Timeout'
    |     property '_idlePrev' -> object with constructor 'TimersList'
    --- property '_idleNext' closes the circle
    at Object.stringify [as serialize] (<anonymous>)
    at Object.emit (/xxx/node_modules/feathers-sync/lib/core.js:47:46)
    at /xxx/node_modules/@feathersjs/feathers/lib/events.js:16:42
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/xxx/node_modules/@feathersjs/feathers/lib/events.js:16:15)
    at /xxx/node_modules/@feathersjs/feathers/node_modules/@feathersjs/commons/lib/hooks.js:115:46
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Module versions (especially the part that’s not working):

    "@feathersjs/authentication-client": "^4.3.11",
    "@feathersjs/authentication-oauth": "^4.3.11",
    "@feathersjs/configuration": "^4.3.11",
    "@feathersjs/errors": "^4.3.11",
    "@feathersjs/express": "^4.3.11",
    "@feathersjs/feathers": "^4.3.11",
    "@feathersjs/socketio": "^4.3.11",
    "@feathersjs/socketio-client": "^4.3.11",
    "feathers-sequelize": "^6.1.0",
    "feathers-sync": "^2.0.0",

NodeJS version: v12.13.0

Not sure if my code is triggering this. Unable to understand as the code was working fine earlier.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dafflcommented, Aug 16, 2020

You just have to make sure that none of your data in the context contain a circular reference. A custom serializer is one option to ensure that, another is to make sure that all params, result or data properties are serializable or serialized (e.g. with their toJSON methods).

0reactions
Artaudcommented, Mar 30, 2021

I had this issue when I was passing sequelize includes across feathers-sync. A simple fix was to use flatted as the serializer as it can serialize objects with circular references.

import {parse, stringify} from 'flatted';

app.configure(sync({
  uri: app.get('redis'),
  serialize: stringify,
  deserialize: parse
}))
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is TypeError: Converting circular structure to JSON?
TypeError: Converting circular structure to JSON occurs when you try to reference your variable name within the JSON object.
Read more >
TypeError: Converting circular structure to JSON - Stack ...
TypeError: Converting circular structure to JSON. It seems that I can get the object logged to the console by using just plain: console.log(object)....
Read more >
TypeError: Converting circular structure to JSON in JS
The "Converting circular structure to JSON" error occurs when we pass an object that contains circular references to the JSON.stringify() method.
Read more >
Converting Circular Structure to JSON - Career Karma
On Career Karma, learn about the restrictions of JSON in the debugging tutorial for converting circular structure to json.
Read more >
How to fix TypeError: Converting circular structure to JSON in ...
To fix this error, you need to make sure that your objects don't contain circular references. One way to do this is to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found