{"id":10653,"library":"common-errors","title":"Common Error Classes for Node.js","description":"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.","status":"abandoned","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/shutterstock/node-common-errors","tags":["javascript","error","errors","common errors","exception","exceptions","validation","standard","argument"],"install":[{"cmd":"npm install common-errors","lang":"bash","label":"npm"},{"cmd":"yarn add common-errors","lang":"bash","label":"yarn"},{"cmd":"pnpm add common-errors","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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).","wrong":"import * as errors from 'common-errors';","symbol":"errors","correct":"const errors = require('common-errors');"},{"note":"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.","wrong":"import { ArgumentError } from 'common-errors';","symbol":"ArgumentError","correct":"const { ArgumentError } = require('common-errors');"},{"note":"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.","wrong":"import { generateClass } from 'common-errors';","symbol":"generateClass","correct":"const { generateClass } = require('common-errors');"}],"quickstart":{"code":"const errors = require('common-errors');\n\ntry {\n  // Example 1: Argument Null Error\n  function processUser(username) {\n    if (!username) {\n      throw new errors.ArgumentNullError('username');\n    }\n    console.log(`Processing user: ${username}`);\n  }\n  processUser(null);\n} catch (error) {\n  console.error('Caught ArgumentNullError:', error.name, error.message);\n  console.error(error.stack);\n}\n\ntry {\n  // Example 2: Custom Error Generation\n  const MyCustomError = errors.generateClass('MyCustomError', 'CustomErrorBase');\n  throw new MyCustomError('Something went wrong in my custom component!');\n} catch (error) {\n  console.error('Caught MyCustomError:', error.name, error.message);\n}\n\n// Example 3: Error with inner error and stack prepending\nfunction fetchData() {\n  try {\n    throw new Error('Original underlying database error');\n  } catch (err) {\n    // Prepend the current stack to the inner error's stack\n    const connectionError = new errors.ConnectionError('Failed to connect to DB.', errors.prependCurrentStack(err));\n    throw connectionError;\n  }\n}\n\ntry {\n  fetchData();\n} catch (error) {\n  console.error('Caught ConnectionError with inner error:', error.name, error.message);\n  console.error('Full stack:', error.stack);\n}","lang":"javascript","description":"Demonstrates the creation and catching of various common error types, custom error generation, and the utility for prepending stack traces from inner errors."},"warnings":[{"fix":"Consider migrating to a more actively maintained error utility library or implementing custom error classes yourself. Evaluate security implications carefully.","message":"This 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.","severity":"breaking","affected_versions":">=1.2.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Thoroughly test compatibility with your target Node.js version. If issues arise, consider alternative, more modern error handling libraries.","message":"Due 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).","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Perform a security audit of your dependencies. If security is critical, replacing this library with a maintained alternative is strongly recommended.","message":"The lack of maintenance implies potential unaddressed security vulnerabilities. Using abandoned software in production can expose applications to risks.","severity":"breaking","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to `require()` an ES Module or attempting to `import` a CommonJS module (like `common-errors`) directly in an ESM context without proper configuration.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported."},{"fix":"Add `const errors = require('common-errors');` at the top of your file to make the error classes available.","cause":"The main `common-errors` module, often imported as `errors`, was not correctly `require()`d or `import`ed before use.","error":"ReferenceError: errors is not defined"},{"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.","cause":"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.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Run `npm install common-errors` to install the package. Double-check the module name in your `require()` statement.","cause":"The `common-errors` package is not installed in the project's `node_modules` directory or there's a typo in the `require()` path.","error":"Error: Cannot find module 'common-errors'"}],"ecosystem":"npm"}