Registry / http-networking / fejl
library4.0.1jsnpmunverified

Fejl is a JavaScript and TypeScript utility library designed to streamline the creation and management of custom error classes in Node.js applications. Currently in its stable v4.0.1 release, Fejl offers a predictable release cadence with major versions typically introducing significant changes like ESM support or Node.js version bumps. Its core functionality revolves around `MakeErrorClass`, which allows developers to define custom error types with default messages and properties, drastically reducing boilerplate compared to native `Error` extension. Key differentiators include static `assert` and `makeAssert` methods for concise conditional error throwing, and a collection of pre-defined HTTP error classes. Fejl aims to improve code readability and maintainability by centralizing error definitions and providing convenient assertion patterns.

npm install fejl
INSTALL
IMPORT
SIG · FEJL
F
fejl
http-networkingjavascriptv4.0.1
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.

MakeErrorClass
✓ import { MakeErrorClass } from 'fejl'
✗ const { MakeErrorClass } = require('fejl')
Fejl v4+ is ESM-only; CommonJS `require` will lead to errors.
NotFound
✓ import { NotFound } from 'fejl'
✗ import NotFound from 'fejl/lib/http'
Specific HTTP errors like `NotFound` are named exports from the main package. Direct path imports might not be stable or work with ESM exports.
InvalidConfigError
✓ class MyCustomError extends MakeErrorClass('Default Message') {}
✗ import { InvalidConfigError } from 'fejl'
`InvalidConfigError` is an example of a *user-defined* error class using `MakeErrorClass`, not a pre-exported symbol from the `fejl` package itself.

Demonstrates creating a custom error class with default properties, handling it, and using static assertion methods with built-in HTTP errors.

import { MakeErrorClass, NotFound } from 'fejl'; // 1. Create a custom error class with a default message and properties class InvalidConfigError extends MakeErrorClass( 'The configuration file is invalid', { infoUrl: 'https://example.com/error-info' } ) {} // 2. Demonstrate throwing and catching a custom error try { throw new InvalidConfigError('Custom message ignored'); } catch (err) { console.log(`Error Name: ${err.name}`); // InvalidConfigError console.log(`Error Message: ${err.message}`); // The configuration file is invalid (default message is used) console.log(`Error Info URL: ${err.infoUrl}`); // https://example.com/error-info console.log(`Is instance of InvalidConfigError? ${err instanceof InvalidConfigError}`); // true } // 3. Use a built-in HTTP error with static assertion class UserNotFoundError extends NotFound {} function getUserById(id) { const user = id === 1 ? { id: 1, name: 'Alice' } : null; // Use static assert to throw if 'user' is falsy UserNotFoundError.assert(user, `User with ID ${id} not found.`); return user; } try { getUserById(2); } catch (err) { console.log(`\nHTTP Error Name: ${err.name}`); // NotFound console.log(`HTTP Error Message: ${err.message}`); // User with ID 2 not found. console.log(`HTTP Status Code: ${err.statusCode}`); // 404 }
Debug
Known issues
breakingFejl v4.0.0 introduced ESM support and removed the `make-error` dependency. This means `require()` statements will no longer work, and projects must use ES module `import` syntax. Additionally, the internal mechanism for extending `Error` changed, which might affect highly customized error implementations.
fix
Migrate your codebase to use ES module `import` statements. If you were directly leveraging `make-error` internals, you may need to refactor your custom error definitions.
affects: >=4.0.0
breakingWith v4.0.0, the minimum supported Node.js version was bumped to Node.js 18. Running `fejl` on older Node.js versions will result in compatibility errors due to package.json `exports` field and other modern syntax.
fix
Upgrade your Node.js runtime environment to version 18 or newer.
affects: >=4.0.0
gotchaWhen creating a custom error class with `MakeErrorClass`, the `message` provided during class definition (e.g., `'Default Message'`) takes precedence over any message passed directly to the constructor when instantiating the error (e.g., `new MyError('My custom message')`). The constructor message will be ignored for the `message` property.
fix
If you need a dynamic message, either define the error class without a default message, or store the dynamic message in a custom property on the error instance, rather than relying on it to override the default `message`.
affects: >=1.0.0
breakingFejl v3.0.0 bumped the minimum supported Node.js version to Node.js 14. While v4 now requires Node 18, users upgrading from versions prior to v3 should be aware of this intermediate breaking change.
fix
Upgrade Node.js to version 14 or higher (or 18+ if using Fejl v4).
affects: 3.0.0 - <4.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module [path] from [path] not supported. Instead change the require of index.js in [path] to a dynamic import() which is available in all CommonJS modules.
Attempting to use `require()` to import `fejl` in a CommonJS module, but `fejl` v4+ is an ES Module.
fix
Change your import statements from `const { Symbol } = require('fejl');` to `import { Symbol } from 'fejl';` and ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`).
TypeError: MakeErrorClass is not a constructor
This error can occur if you're trying to use `new MakeErrorClass()` directly, or if `MakeErrorClass` itself wasn't correctly imported in a CJS context when it's an ESM export, leading to an undefined import.
fix
Ensure `MakeErrorClass` is imported correctly using `import { MakeErrorClass } from 'fejl'` for ESM projects. The function itself returns a class constructor, so you would extend it, not instantiate it directly: `class MyError extends MakeErrorClass(...) {}`.
Error: The configuration file is invalid (when I passed a different message to the constructor)
Fejl's `MakeErrorClass` prioritizes the default message defined when creating the error class over any message argument passed to the constructor during instantiation.
fix
This is the intended behavior of `fejl`. If you need a dynamic error message, either create the class without a default message: `class MyError extends MakeErrorClass() {}`, or pass your dynamic message as a custom property: `new MyError(null, { myDynamicMessage: '...' })`.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
fejl — npm install fejl · libregistry