Registry / web-framework / common-errors

common-errors

JSON →
library1.2.0jsnpmunverified

The `common-errors` package provides a comprehensive suite of custom error classes for Node.js, designed to offer more specific error types than native JavaScript `Error` objects. Originally intended to mirror error types found in other modern languages, it includes classes like `AlreadyInUseError`, `ArgumentError`, `NotFoundError`, and `AuthenticationRequiredError`. Key features highlighted in its documentation include the ability to append stack traces from asynchronously generated errors, dynamically generate custom error classes, and map HTTP status codes to errors for web service integration. The current stable version is 1.2.0. However, the package has not seen active development or updates in many years, with its last release dating back to 2017. Consequently, it is no longer actively maintained.

npm install common-errors
INSTALL
IMPORT
SIG · COMMON-ERRORS
C
common-errors
web-frameworkjavascriptv1.2.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

errors
✓ const errors = require('common-errors');
✗ import * as errors from 'common-errors';
This package is a CommonJS module from an older era. Direct ESM `import` will likely fail without specific Node.js configuration (e.g., 'type: module' in package.json or transpilation).
ArgumentError
✓ const { ArgumentError } = require('common-errors');
✗ import { ArgumentError } from 'common-errors';
While CommonJS modules can often be destructured, using `require` for this older library is safer than an ESM `import` directly. The library's structure (`errors.ArgumentError`) suggests a single primary export.
generateClass
✓ const { generateClass } = require('common-errors');
✗ import { generateClass } from 'common-errors';
As a utility function, it's typically accessed via the main `errors` object or potentially destructured from the `require` call. ESM `import` is not natively supported.

Demonstrates the creation and catching of various common error types, custom error generation, and the utility for prepending stack traces from inner errors.

const errors = require('common-errors'); try { // Example 1: Argument Null Error function processUser(username) { if (!username) { throw new errors.ArgumentNullError('username'); } console.log(`Processing user: ${username}`); } processUser(null); } catch (error) { console.error('Caught ArgumentNullError:', error.name, error.message); console.error(error.stack); } try { // Example 2: Custom Error Generation const MyCustomError = errors.generateClass('MyCustomError', 'CustomErrorBase'); throw new MyCustomError('Something went wrong in my custom component!'); } catch (error) { console.error('Caught MyCustomError:', error.name, error.message); } // Example 3: Error with inner error and stack prepending function fetchData() { try { throw new Error('Original underlying database error'); } catch (err) { // Prepend the current stack to the inner error's stack const connectionError = new errors.ConnectionError('Failed to connect to DB.', errors.prependCurrentStack(err)); throw connectionError; } } try { fetchData(); } catch (error) { console.error('Caught ConnectionError with inner error:', error.name, error.message); console.error('Full stack:', error.stack); }
Debug
Known issues
breakingThis package is effectively abandoned. The last version (1.2.0) was published 9 years ago (as of April 2026). This means there will be no new features, bug fixes, or security patches.
fix
Consider migrating to a more actively maintained error utility library or implementing custom error classes yourself. Evaluate security implications carefully.
affects: >=1.2.0
gotchaThe package is primarily a CommonJS module and does not natively support ES Module (`import`) syntax. Attempting to `import` it directly in a modern ESM-only project will likely result in `ERR_REQUIRE_ESM` or similar errors.
fix
Use `const errors = require('common-errors');` for CommonJS environments. For ESM projects, you might need Node.js's interoperability features or a bundler to consume this CJS package, or use dynamic `import()` if applicable.
affects: >=1.0.0
gotchaDue to its age (last updated 2017), `common-errors` may not be fully compatible with very recent Node.js versions or modern JavaScript language features (e.g., `async/await` error handling patterns).
fix
Thoroughly test compatibility with your target Node.js version. If issues arise, consider alternative, more modern error handling libraries.
affects: >=1.2.0
breakingThe lack of maintenance implies potential unaddressed security vulnerabilities. Using abandoned software in production can expose applications to risks.
fix
Perform a security audit of your dependencies. If security is critical, replacing this library with a maintained alternative is strongly recommended.
affects: >=1.2.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Attempting to `require()` an ES Module or attempting to `import` a CommonJS module (like `common-errors`) directly in an ESM context without proper configuration.
fix
If `common-errors` is the CJS module: use `const errors = require('common-errors');`. If your project is ESM and you need to consume this CJS module, ensure Node.js interoperability is configured, or use a dynamic `import()` if suitable.
ReferenceError: errors is not defined
The main `common-errors` module, often imported as `errors`, was not correctly `require()`d or `import`ed before use.
fix
Add `const errors = require('common-errors');` at the top of your file to make the error classes available.
TypeError: Class extends value undefined is not a constructor or null
This can occur if `errors.generateClass` is called with an invalid base class or if the `errors` object itself is `undefined` due to an incorrect import. It can also happen when attempting to extend a non-constructor.
fix
Verify that `common-errors` is correctly `require()`d and that `generateClass` is used with valid arguments. Ensure the base class (second argument) if provided, is a valid constructor function.
Error: Cannot find module 'common-errors'
The `common-errors` package is not installed in the project's `node_modules` directory or there's a typo in the `require()` path.
fix
Run `npm install common-errors` to install the package. Double-check the module name in your `require()` statement.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
common-errors — npm install common-errors · libregistry