diff --git a/lib/fs.js b/lib/fs.js index e2996ba9ca4ef6..1a72361e8cf425 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -282,8 +282,8 @@ let showExistsDeprecation = true; function existsSync(path) { try { path = getValidatedPath(path); - } catch { - if (showExistsDeprecation) { + } catch (err) { + if (showExistsDeprecation && err?.code === 'ERR_INVALID_ARG_TYPE') { process.emitWarning( 'Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187', );