Registry / serialization / layerr

layerr

JSON →
library3.0.0jsnpmunverified

Layerr is a lightweight, dependency-free error wrapping utility for both Node.js and browser environments, designed to enhance error handling in complex applications. Currently at version 3.0.0, it provides a structured way to chain errors, attach arbitrary contextual information, and rename error types dynamically. Layerr is based on the concepts of `VError` but significantly lighter, stripping away Node.js core utility dependencies to ensure better browser compatibility and smaller bundle sizes. It is written in TypeScript and compiled to JavaScript, making it suitable for modern development workflows. The package maintains an active release cadence, focusing on stability and minimal overhead, differentiating itself by its lean design, ESM-only distribution (since v3), and strong TypeScript support for improved developer experience.

npm install layerr
INSTALL
IMPORT
SIG · LAYERR
L
layerr
serializationjavascriptv3.0.0
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.

Layerr
import { Layerr } from 'layerr'
const { Layerr } = require('layerr')
Layerr is an ESM library since v3; CommonJS `require` is not supported for direct import.
setGlobalName
import { setGlobalName } from 'layerr'
import Layerr from 'layerr'; Layerr.setGlobalName(...)
`setGlobalName` is a named export, not a method on the `Layerr` class itself, and should be imported directly.
Layerr (Type)
import type { Layerr } from 'layerr'
When only importing the type for TypeScript, use `import type` for better tree-shaking and explicit intent.

This quickstart demonstrates creating and wrapping errors with Layerr, attaching contextual information, and dynamically renaming the error type. It simulates an asynchronous operation that may fail and shows how to catch and re-throw an error using Layerr for enhanced debugging and error reporting.

import { Layerr, setGlobalName } from 'layerr'; async function simulateTask() { return new Promise((resolve, reject) => { // Simulate an async operation that might fail setTimeout(() => { const shouldFail = Math.random() > 0.5; if (shouldFail) { reject(new Error('Original database error')); } else { resolve('Data fetched successfully'); } }, 100); }); } async function runExample() { setGlobalName('MyApplicationError'); // Dynamically change the error name try { await simulateTask(); console.log('Task completed without errors!'); } catch (originalError) { // Wrap the original error with Layerr, adding context info const wrappedError = new Layerr( { cause: originalError, info: { code: 5001, severity: 'high', userId: 'user-abc-123' } }, 'Failed to retrieve critical data from the backend.' ); console.error(`Caught an error: ${wrappedError.name} [${wrappedError.info.code}]: ${wrappedError.message}`); console.error(`Original cause: ${wrappedError.cause?.message}`); console.error('Additional info:', Layerr.info(wrappedError)); } } runExample();
Debug
Known issues
breakingLayerr v3 and above is an ECMAScript Module (ESM) library only. Direct `require()` statements for importing `Layerr` will fail.
fix
Update your import statements to use `import { Layerr } from 'layerr'` syntax. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` file extensions).
affects: >=3.0.0
gotchaWhen accessing information attached to a Layerr instance, always use the static `Layerr.info(error)` method, rather than trying to access an `info` property directly on the error object, as the property might not be directly available or correctly typed.
fix
Instead of `error.info.code`, use `Layerr.info(error).code` for reliable access to attached data.
affects: >=1.0.0
gotchaThe `setGlobalName` function changes the default `name` property for all *newly created* Layerr instances globally. This can lead to unexpected behavior if not managed carefully in applications with multiple error types or concurrent operations.
fix
Use `setGlobalName` judiciously, preferably at application startup for a consistent error name, or revert it to `null` if temporary changes are needed: `setGlobalName(null)`.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ...layerr/dist/index.js from ... not supported.
Attempting to import Layerr v3+ using CommonJS `require()` syntax in a non-ESM environment.
fix
Change `const { Layerr } = require('layerr')` to `import { Layerr } from 'layerr'`. Ensure your project `package.json` has `"type": "module"` or use `.mjs` file extensions for ESM files.
Property 'info' does not exist on type 'Layerr'.
Trying to directly access an `info` property on a `Layerr` instance without using the static `Layerr.info()` helper.
fix
Use the static method `const { code } = Layerr.info(err);` to correctly retrieve attached information from a Layerr instance.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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