{"id":10622,"library":"check-error","title":"Error Comparison and Information Utility","description":"check-error is a JavaScript utility library designed for robust error inspection and comparison in both Node.js and browser environments. Currently at stable version 2.1.3, it provides functions to retrieve error information, such as constructor names and messages, and to determine compatibility between errors based on their instance, constructor, or message content. It is a foundational utility often employed within testing frameworks, particularly Chai, for asserting error conditions. Since version 2.0.0, it is an ESM-only module, requiring modern JavaScript environments (Node.js 16+, Firefox 102+, Chromium Edge+). Releases are infrequent, focusing on maintenance and modernizing the codebase to align with current JavaScript standards. Its key differentiator is providing a standardized set of primitives for error interrogation, abstracted away from environment-specific quirks, which simplifies error handling logic across different contexts. This ensures consistent behavior when dealing with various types of errors and their properties.","status":"active","version":"2.1.3","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/chaijs/check-error","tags":["javascript","check-error","error","chai util"],"install":[{"cmd":"npm install check-error","lang":"bash","label":"npm"},{"cmd":"yarn add check-error","lang":"bash","label":"yarn"},{"cmd":"pnpm add check-error","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v2.0.0, check-error is an ESM-only module. CommonJS `require` is no longer supported.","wrong":"const checkError = require('check-error');","symbol":"checkError","correct":"import * as checkError from 'check-error';"},{"note":"Individual utility functions can be imported as named exports for tree-shaking benefits.","symbol":"compatibleConstructor, getMessage","correct":"import { compatibleConstructor, getMessage } from 'check-error';"}],"quickstart":{"code":"import * as checkError from 'check-error';\n\nclass CustomError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = 'CustomError';\n  }\n}\n\nfunction potentiallyFailingOperation(shouldThrow: boolean, type: string = 'TypeError'): void {\n  if (shouldThrow) {\n    if (type === 'CustomError') {\n      throw new CustomError('Something went wrong with custom logic.');\n    } else {\n      throw new TypeError('Invalid data format received.');\n    }\n  }\n}\n\ntry {\n  potentiallyFailingOperation(true);\n} catch (e: unknown) {\n  if (e instanceof Error) {\n    console.log(`Caught error: ${e.message}`);\n    console.log(`Constructor name: ${checkError.getConstructorName(e)}`);\n    console.log(`Is compatible with TypeError? ${checkError.compatibleConstructor(e, TypeError)}`);\n    console.log(`Is compatible with message 'data format'? ${checkError.compatibleMessage(e, 'data format')}`);\n    console.log(`Is compatible with CustomError? ${checkError.compatibleConstructor(e, CustomError)}`);\n  }\n}\n\ntry {\n  potentiallyFailingOperation(true, 'CustomError');\n} catch (e: unknown) {\n  if (e instanceof Error) {\n    console.log(`\\nCaught another error: ${e.message}`);\n    console.log(`Constructor name: ${checkError.getConstructorName(e)}`);\n    console.log(`Is compatible with TypeError? ${checkError.compatibleConstructor(e, TypeError)}`);\n    console.log(`Is compatible with CustomError? ${checkError.compatibleConstructor(e, CustomError)}`);\n  }\n}","lang":"typescript","description":"Demonstrates catching different error types and using `check-error` to inspect their constructor names, messages, and compatibility with other error types."},"warnings":[{"fix":"Migrate your project to use ESM `import` syntax. Ensure your Node.js environment is v16 or higher, or use modern browsers (Firefox 102+, Chromium Edge+).","message":"Version 2.0.0 introduced a breaking change, converting the module to ESM-only. CommonJS `require()` is no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your environment to meet the minimum requirements (Node.js >=16, Firefox >=102, Chromium Edge/Chrome/Safari latest).","message":"With the shift to ESM-only in v2.0.0, support for older environments including Node.js versions below 16, Firefox versions less than 102, and all versions of Internet Explorer and older Edge (v18 and below) was dropped.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade to version 2.1.2 or newer to ensure robust handling of invalid inputs in message comparisons.","message":"Prior to v2.1.2, the `compatibleMessage` function might not correctly handle invalid inputs, potentially leading to unexpected behavior or errors when comparing messages.","severity":"gotcha","affected_versions":"<2.1.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const checkError = require('check-error');` to `import * as checkError from 'check-error';` and ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in package.json).","cause":"Attempting to `require()` the `check-error` package in a CommonJS environment after upgrading to v2.0.0 or later.","error":"ERR_REQUIRE_ESM"},{"fix":"Verify that `checkError` is correctly imported as `import * as checkError from 'check-error';` and that the method name (`compatibleMessage` or others) is spelled correctly and exists in the current version of the library.","cause":"This error is unlikely for `compatibleMessage` specifically, but if a function from the `checkError` object is not found, it implies an incorrect import or an attempt to use a non-existent method.","error":"TypeError: checkError.compatibleMessage is not a function"}],"ecosystem":"npm"}