Skip to content

NeaByteLab/Stackz

Repository files navigation

Stackz Module type: CJS+ESM npm version JSR Node.js CI

Beautiful stack trace formatter with source code context for JavaScript.

Demo

Features

  • Cross-runtime support - Works in Deno, Node.js, Bun, and browsers
  • Source code context - Shows actual code around error locations (detailed mode)
  • Two formatting styles - Compact and detailed stack traces
  • ANSI colors - Beautiful terminal output with syntax highlighting

Installation

Choose your preferred package manager:

# npm package
npm install @neabyte/stackz

# Deno module
deno add jsr:@neabyte/stackz

Usage

import Stackz from '@neabyte/stackz'

try {
  // Your code that might throw
  throw new Error('Something went wrong')
} catch (error) {
  // Compact format without source context
  console.log(Stackz.format(error, 'compact'))
  // Detailed format with source context
  console.log(await Stackz.format(error, 'detailed'))
}

Formats

Compact

TypeError  Cannot read properties of undefined (reading 'property')
  → createTypeError @ index.ts:5:14
  → index.ts:15:3

Detailed

TypeError  Cannot read properties of undefined (reading 'property')

Path: /path/to/project/index.ts:5:14
  2 |
  3 | function createTypeError() {
  4 |   const obj = undefined as any
  5     return obj.property // This will create TypeError with real stack
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6 | }

Call Stack:
 • createTypeError → index.ts:5:14
 • anonymous → index.ts:15:3

License

This project is licensed under the MIT license. See the LICENSE file for more info.