This recipe transforms the usage of types.isNativeError to use Error.isError() to handle Node.js DEP0197.
What It Does
This codemod replaces:
types.isNativeError() calls with Error.isError()
- Removes unnecessary
util imports when no longer needed
Before/After
Before:import { types } from "node:util";
if (types.isNativeError(err)) {
// handle the error
}
After:if (Error.isError(err)) {
// handle the error
}
Before:const { types } = require("node:util");
if (types.isNativeError(err)) {
// handle the error
}
After:if (Error.isError(err)) {
// handle the error
}
Usage
Run this codemod on your project:
npx codemod node/userland/types-is-native-error
Error.isError() is now the preferred way to check if a value is an Error object. This method is available globally without requiring any imports.