> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
> Use this file to discover all available pages before exploring further.

# types.isNativeError to Error.isError

> Migrate deprecated types.isNativeError() to Error.isError() for Node.js DEP0197

This recipe transforms the usage of `types.isNativeError` to use `Error.isError()` to handle Node.js [DEP0197](https://nodejs.org/api/deprecations.html#DEP0197).

## What It Does

This codemod replaces:

* `types.isNativeError()` calls with `Error.isError()`
* Removes unnecessary `util` imports when no longer needed

## Before/After

<Tabs>
  <Tab title="ESM">
    **Before:**

    ```javascript theme={null}
    import { types } from "node:util";

    if (types.isNativeError(err)) {
      // handle the error
    }
    ```

    **After:**

    ```javascript theme={null}
    if (Error.isError(err)) {
      // handle the error
    }
    ```
  </Tab>

  <Tab title="CommonJS">
    **Before:**

    ```javascript theme={null}
    const { types } = require("node:util");

    if (types.isNativeError(err)) {
      // handle the error
    }
    ```

    **After:**

    ```javascript theme={null}
    if (Error.isError(err)) {
      // handle the error
    }
    ```
  </Tab>
</Tabs>

## Usage

Run this codemod on your project:

```bash theme={null}
npx codemod node/userland/types-is-native-error
```

<Tip>
  `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.
</Tip>

## Related Deprecations

* [DEP0197: types.isNativeError()](https://nodejs.org/api/deprecations.html#DEP0197)
