JSON.stringify抛出RangeError:巨大对象的字符串长度无效

时间:2021-08-28 17:32:33

As the title implies I'm trying to stringify huge JavaScript Object with JSON.stringify in my Node.js app. The objects are - again - huge (tens of mega bytes), they don't contain any functions. I need to write the serialized objects to a file. What I'm getting now is this:

正如标题所暗示的那样,我正试图在我的Node.js应用程序中使用JSON.stringify对巨大的JavaScript对象进行字符串化。对象 - 再次 - 巨大(几十兆字节),它们不包含任何函数。我需要将序列化对象写入文件。我现在得到的是:

RangeError: Invalid string length
  at Object.stringify (native)
  at stringifyResult (/my/file.js:123:45) -> line where I use JSON.stringify

Any idea how to solve that issue?

知道如何解决这个问题吗?

1 个解决方案

#1


7  

I too have seen this unhelpful/misleading nodejs error message, so I booked an issue over at nodejs github

我也看到了这个无用/误导性的nodejs错误消息,所以我在nodejs github上预订了一个问题

RangeError: Invalid string length --- it should be saying Out Of Memory

RangeError:无效的字符串长度---它应该是Out Of Memory

#1


7  

I too have seen this unhelpful/misleading nodejs error message, so I booked an issue over at nodejs github

我也看到了这个无用/误导性的nodejs错误消息,所以我在nodejs github上预订了一个问题

RangeError: Invalid string length --- it should be saying Out Of Memory

RangeError:无效的字符串长度---它应该是Out Of Memory