This is actually an issue found in recursive-readdir-sync library.
The device is a flash drive. What happened is that fs.readdirSync returns an array of file name entries some of which fs.statSync would throw error reading.
Fun fact: Doing $ ls -a in the shell did not reveal the files that fs.readdirSync did.
I am not sure whether this is a known issue of NodeJS or something of even lower level is going on (like OS or the device itself).
UPDATED
- OS: MacOS (10.14.1)
- Device: SanDisk Extreme Portable SSD 250GB - 2TB Solid State Drive