{"id":13351,"library":"iserror","title":"iserror: Error Object Type Check","description":"The `iserror` package, currently at version `0.0.2`, provides a lightweight utility function designed to determine if a given JavaScript value is an `Error` object. Released several years ago, it offers a simple, cross-environment solution for both Node.js and browser environments, as indicated by its keywords. Unlike Node.js's built-in `util.isError` (which has been deprecated since Node.js 10 and eventually removed), `iserror` functions as a standalone CommonJS module. Its primary differentiator is its singular focus on this specific type-checking task without introducing additional dependencies, providing a basic `require` interface for quick integration into projects that prefer a dedicated utility over direct `instanceof Error` checks or more complex custom type-guarding logic. Its release cadence appears to be minimal, reflecting a stable but largely unmaintained state since its initial publication.","status":"abandoned","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/yefremov/iserror","tags":["javascript","test","object","error","iserror","browser","node"],"install":[{"cmd":"npm install iserror","lang":"bash","label":"npm"},{"cmd":"yarn add iserror","lang":"bash","label":"yarn"},{"cmd":"pnpm add iserror","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module, primarily intended for use with `require()`. Attempting to use ESM `import` directly may lead to errors depending on your build setup.","wrong":"import isError from 'iserror';","symbol":"isError","correct":"const isError = require('iserror');"},{"note":"While natively CJS, bundlers like Webpack or Rollup, or transpilers like Babel, can often create an ESM-compatible wrapper allowing for a default import. Named imports are not supported.","wrong":"import { isError } from 'iserror';","symbol":"isError (ESM wrapper)","correct":"import isError from 'iserror'; // via bundler or Babel"}],"quickstart":{"code":"const isError = require('iserror');\n\nfunction processValue(value) {\n  if (isError(value)) {\n    console.log(`Received an error: ${value.message}`);\n    // Log error details, send to error tracking, etc.\n    return 'Error handled.';\n  } else if (typeof value === 'number') {\n    console.log(`Processing number: ${value}`);\n    return `Result: ${value * 2}`;\n  } else {\n    console.log(`Received unknown type: ${typeof value}`);\n    return 'Unhandled value type.';\n  }\n}\n\nconsole.log(processValue(new Error('Something went wrong!')));\nconsole.log(processValue(123));\nconsole.log(processValue('hello'));\nconsole.log(processValue(new TypeError('Invalid type.')));\nconsole.log(processValue({ message: 'Not a true error object' }));","lang":"javascript","description":"Demonstrates how to use `isError` to differentiate between Error objects and other JavaScript values in a processing function."},"warnings":[{"fix":"Use `const isError = require('iserror');` for CommonJS environments. For ESM projects, rely on your bundler's CJS compatibility or consider modern alternatives like `value instanceof Error`.","message":"The `iserror` package is a CommonJS module. Direct ESM `import` statements without a bundler or transpiler might fail with 'ERR_REQUIRE_ESM' or similar errors in Node.js environments.","severity":"gotcha","affected_versions":"<=0.0.2"},{"fix":"For new code, prefer `value instanceof Error` directly. For example: `if (myValue instanceof Error) { /* handle error */ }`. This provides the same functionality without an extra module.","message":"This package is very old (version 0.0.2) and appears to be unmaintained. Modern JavaScript environments typically prefer using the built-in `value instanceof Error` check, which is more idiomatic and doesn't require an external dependency.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"Evaluate your project's needs. For critical applications, `instanceof Error` is a more robust and future-proof solution maintained by the JavaScript engine itself.","message":"As an unmaintained utility, `iserror` may not receive updates for new JavaScript features, edge cases in different environments, or potential subtle bugs. Its core logic is simple, but long-term reliance might carry risks.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you have `const isError = require('iserror');` at the top of your CommonJS file, or that your build system correctly transpiles ESM imports if you're using `import isError from 'iserror';`.","cause":"Attempting to use `isError` without properly importing or requiring it, or using an ESM `import` in a pure CommonJS context without transpilation.","error":"ReferenceError: isError is not defined"},{"fix":"Confirm that you are directly calling the result of `require('iserror')`, as it exports the function directly. `const isError = require('iserror'); isError(myValue);`","cause":"This error often occurs if the import or require statement didn't correctly resolve `iserror` to the function itself, possibly due to incorrect module syntax (e.g., `require('iserror').default` or an incorrect named import if it were an ESM module).","error":"TypeError: isError is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null}