"TypeError: Do not know how to serialize a BigInt"

Hi NR folks!

I'm facing a strange sporadic error from the file in node. Sometimes this happens a few times a day and sometimes not at all. As seen below, the node should save all received MQTT data as a log. The MQTT in node receives a bunch of records from different topics more or less every half a minute.

Does anyone have an idea how to fix this error? I've been looking around for a while and am assuming this might be a timing issue. I don't think this is a general problem as it has been working for a while.

"TypeError: Do not know how to serialize a BigInt"

image

image

Thank you

Firstly, BigInt is a JavaScript data type (ref)

2nd thing to know, is a BigInt cannot be directly serialised to JSON

Lastly, something somewhere in your flow (or a contrib node) code is generating values of type BigInt and (at a guess since you did not share any flow or example data or what version of node-red you are running) I suspect your function node is arrempting to serialise (likely JSON.stringify) the data before being written to file.


If you want further help, you will need to

  • identify where the error occurs (click the long hexadecimal number in the debug error)
  • identify where the data with BigInt comes from
  • grab a sample of this data and post it along with a demo flow that exhibits this problem

Hi Steve

Got it! The 2.0.6 version is used.

As mentioned, all errors are pointing to the file in node.

The code in the function is quite basic. I add the current date information to the payload and set up the file name for each received topic.
image

As I said, the whole project works fine, all topics are written to the file and so on. But really sometimes it comes to this error. The topic data should always be the same. Seems it's hard to debug because I can't find where BigInt is used?

Do you think this can be a problem if, for example, 20 MQTT topics are received within a few milliseconds?

potentially yes - you can space them out using a delay node (set to Rate Limit mode) (add a rate limit between function and file node - start with 5 msg per 1 sec to start with)

I suspect the CBOR node is returning a big int - what is that node?

Also, V2.0.6 does support displaying bigint in the debug sidebar so pipe the Function node to a debug node and when you get an error, take a look at the data.

Laslty, add a catch node linked to a debug node (set to show the Complete Message) - show us the content of the complete msg next time you get an error

Thank you very much for these suggestions.

I finally found out that CBOR sometimes receives too large data and this is not due to a node red bug or something related. The file in node then cannot then process this data and throws this error.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.