Registry / testing / iserror

iserror

JSON →
library0.0.2jsnpmunverified

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.

npm install iserror
INSTALL
IMPORT
SIG · ISERROR
I
iserror
testingjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isError
const isError = require('iserror');
import isError from 'iserror';
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.
isError (ESM wrapper)
import isError from 'iserror'; // via bundler or Babel
import { isError } from 'iserror';
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.

Demonstrates how to use `isError` to differentiate between Error objects and other JavaScript values in a processing function.

const isError = require('iserror'); function processValue(value) { if (isError(value)) { console.log(`Received an error: ${value.message}`); // Log error details, send to error tracking, etc. return 'Error handled.'; } else if (typeof value === 'number') { console.log(`Processing number: ${value}`); return `Result: ${value * 2}`; } else { console.log(`Received unknown type: ${typeof value}`); return 'Unhandled value type.'; } } console.log(processValue(new Error('Something went wrong!'))); console.log(processValue(123)); console.log(processValue('hello')); console.log(processValue(new TypeError('Invalid type.'))); console.log(processValue({ message: 'Not a true error object' }));
Debug
Known issues
gotchaThe `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.
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`.
affects: <=0.0.2
deprecatedThis 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.
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.
affects: >=0.0.1
gotchaAs 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.
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.
affects: >=0.0.1
Errors
Common errors & fixes
ReferenceError: isError is not defined
Attempting to use `isError` without properly importing or requiring it, or using an ESM `import` in a pure CommonJS context without transpilation.
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';`.
TypeError: isError is not a function
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).
fix
Confirm that you are directly calling the result of `require('iserror')`, as it exports the function directly. `const isError = require('iserror'); isError(myValue);`
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
iserror — npm install iserror · libregistry