node.jsloggingchild-processconsole.log

"TypeError: second argument to Function.prototype.apply must be an Array-like object" in node childProcess internal file


Disclaimer: Sorry for lack of infos on this error. I let it there for reference because I couldn't find another question on the subject and it could put people on a track for a solution [Edit] I managed to solve it, see answer below

I'm spawning a child process to run my tests so that I can rerun them if they fail while taking in account any modification made in the test code (since ES6 import this is very difficult since we can't no more clear import cache and reimport files)

I always get the TypeError: second argument to Function.prototype.apply must be an Array-like object error after a lot of tests has passed (usually 1200+) and a lot of content has been logged.

Some notes:

Here is a screenshot where you can see the code / stack trace

enter image description here

Tried on Node v18.18.2 and v20.11.1

I can provide the code, but it's huge and I'm not sure it will be relevant here. Let me know if you need further details or code examples.


Solution

  • EDIT: Having this error 2 month after this and with the below fix not working, I spend days investigating to notice that it's finally a ts-node problem with console.log or memory handling. I used bun and did the same without a problem.

    I finally managed to get rid of this error by deleting a line that logged a very long array of numbers in a for loop.

    So I went from

    console.log('a string', veryLongNumberArray)
    

    to

    console.log('a string')
    

    Sorry that I don't have more clues but those lines, I let that for further references and because I think it may help at least to give a track for a solution