npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@moyal/js-error

v1.0.2

Published

A modern, extensible JavaScript error class with native cause support, recursive serialization, full stack tracing, and developer-friendly utilities. Designed for structured logging and forward-compatible error handling in modern applications.

Downloads

6

Readme

moyal.js.error

license npm version jsDelivr CDN minzipped size

A modern, extensible JavaScript error class with native cause support, recursive serialization, full stack tracing, and developer-friendly utilities. Designed for structured logging and forward-compatible error handling in modern applications.

Information

Table of Contents

Installation

npm install @moyal/js-error

Importing

In Node.js (ES Module)

import { MoyalError } from "@moyal/js-error";

In Node.js (CommonJS)

const { MoyalError } = require("@moyal/js-error");

In the Browser (ES Module via CDN)

<!-- From jsDelivr CDN (minified version) -->
<script type="module">
  import "https://cdn.jsdelivr.net/npm/@moyal/[email protected]/dist/moyal.error.umd.min.js";
</script>

<!-- From jsDelivr CDN (non minified version with documentation) -->
<script type="module">
  import "https://cdn.jsdelivr.net/npm/@moyal/[email protected]/dist/moyal.error.umd.js";
</script>

Or using unpkg:

<script type="module">
  import "https://unpkg.com/@moyal/[email protected]/dist/moyal.error.umd.min.js";
</script>

Features

  • Native cause Support: Utilizes ES2022's standardized error chaining with automatic fallback for older runtimes.
  • Recursive toString and fullStack: View entire error chains clearly, including nested stack traces.
  • Structured Logging Ready: Includes toJSON() method with name, timestamp, type, message, stack, and full cause serialization.
  • Enable extending native Error type with toJSON() method with name, type, message, stack, and full cause serialization.
  • Cause Chain Inspection: Built-in printCauseChain() for clean, indented cause inspection.
  • Minimal & Self-contained: Zero dependencies. Works seamlessly in Node.js and modern browsers.
  • Forward-Compatible Design: Fully embraces modern JavaScript error handling without legacy bloat.

Quick Start

import { MoyalError } from "@moyal/js-error";
MoyalError.extendNativeError(); /* extends native `Error` class with `toJSON` function */

try {
    try {
        throw new Error("Root failure");
    } catch (inner) {
        throw new MoyalError("Wrapping error", { cause: inner });
    }
} catch (err) {
    console.log(err.toString());
    console.log(err.fullStack);
    console.log(JSON.stringify(err.toJSON(), null, 2));
}

/*
Output (formatted):

MoyalError: Wrapping error
    at ...
Caused by...
    Error: Root failure
        at ...

And JSON output:

{
  "name": "MoyalError",
  "message": "Wrapping error",
  "stack": "...",
  "timestamp": "2025-05-09T...",
  "cause": {
    "name": "Error",
    "message": "Root failure",
    ...
  },
  "type": "MoyalError"
}

Note: If we don't call MoyalError.extendNativeError(), the inner error (cause) won't be serialized properly — it will appear as {} in the JSON output.

*/

For more code examples, see also "/examples" and (or) "/test/units" in GitHub Repository.

Why Use moyal.js.error

  • Error chaining is now a standard — cause is part of modern JavaScript (ES2022+), and this library builds on it properly.
  • Your errors deserve structure — cleanly formatted, timestamped, and serializable errors are easier to debug and analyze.
  • Minimal, not minimalistic — it gives you everything you need (recursive stack, JSON, inspection) and nothing you don’t.
  • Safe fallback — gracefully simulates cause for environments that don’t support it yet, without breaking anything.
  • Framework-ready — integrate with loggers, API responses, or monitoring systems without needing adapters or custom serializers.
  • Drop-in convenience — replace any native throw new Error(...) with throw new MoyalError(...) and gain all the benefits instantly.

Compatibility

| Feature | Supported In | Notes | |---------------------------|---------------------------------------------------------------|-----------------------------------------------------------------------| | Native cause | ✅ Node.js ≥ 16.9✅ Chrome ≥ 93✅ Firefox ≥ 91✅ Edge ≥ 93 | Full ES2022 support | | Fallback cause | ✅ Yes | Automatically simulated in older runtimes | | Stack Trace | ✅ Yes | Includes full stack plus recursive fullStack for nested errors | | toJSON() | ✅ Yes | Includes name, message, stack, timestamp, cause, type | | Module Format | ✅ ES Module | "type": "module" in package.json | | Runtime Environments | ✅ Node.js✅ Modern Browsers (ES2020+) | Full support recommended in ES2022+ |

Requirements

  • Runtime: ES2020+ (Node.js ≥ 14, modern browsers)
  • Native cause support recommended for full functionality (Node.js ≥ 16.9 or equivalent browser)
  • Dependencies: None – zero-dependency library
  • Module Format: ES Module (importable in "type": "module" or via bundlers)

You can use it directly in modern JavaScript projects without any external libraries or polyfills.

Version Access

Access the library version directly:

import * as myLib from "@moyal/js-error";

myLib.Version // → e.g., "1.0.2"

License

MIT License - free to use, modify, and distribute.

Author: Ilan Moyal

Website: https://www.moyal.es

GitHub: Ilan Moyal

LinkedIn: Ilan Moyal