watch: fix null `fileName` on windows systems
This fixes a Node.js crash when running on Windows with --watch
.
The issue is that fs.watch()
sometimes returns null
for the filename
as described in the official Node.js documentation.
The thrown error:
node:internal/validators:162
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "paths[1]" argument must be of type string. Received null
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at validateString (node:internal/validators:162:11)
at resolve (node:path:171:9)
at FSWatcher.<anonymous> (node:internal/watch_mode/files_watcher:99:30)
at FSWatcher.emit (node:events:514:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:215:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
Node.js v20.5.1
There is also a Stack Overflow question related to this issue.