node
node copied to clipboard
watch runner crash with ERR_INVALID_ARG_TYPE
Version
v18.16.0
Platform
Microsoft Windows NT 10.0.22621.0 x64
Subsystem
internal/watch_mode/files_watcher.js
What steps will reproduce the bug?
Use node --watch script.js
How often does it reproduce? Is there a required condition?
When third-party tool written in Java works on the same directory.
What is the expected behavior? Why is that the expected behavior?
Normal running.
What do you see instead?
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
at new NodeError (node:internal/errors:399:5)
at validateString (node:internal/validators:163:11)
at resolve (node:path:167:9)
at FSWatcher.<anonymous> (node:internal/watch_mode/files_watcher:94:30)
at FSWatcher.emit (node:events:513:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:215:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
Additional information
The reason for the error is the call resolve
without checking if the name is not null
https://github.com/nodejs/node/blob/9398ff1dea564807378f485deae2eecaf5fde993/lib/internal/watch_mode/files_watcher.js#L93-L94
Regardles to documentation:
filename is not always guaranteed to be provided. Therefore, don't assume that filename argument is always provided in the callback, and have some fallback logic if it is null.
https://github.com/nodejs/node/pull/49891