fs.writeFileSync TypeError: lazyErrmapGet is not a function or its return value is not iterable

Viewed 493

fs.writeFileSync TypeError: lazyErrmapGet is not a function or its return value is not iterable

I faced this issue while using fs.writeFileSync from fs-extra as following inside one of my gulp task :

fs.writeFileSync(
    `${docsTarget}/content-list.json`,
    JSON.stringify(contentList, null, 4),
    { flag: 'w' },
    'utf8'
 );

Now I am not able to reproduce it, but want to know what may be the cause for the same!

Following are the logs: enter image description here

1 Answers

In my experience it comes from returning a non-array to a result expecting an array. The called function may usually return an array, but has less often used branch where it returns a non-array.

Apparently an iterator returning a non-array can be used to fill an array. So the runtime Javascript mistakenly thinks that is what is intended.

Related