Registry / testing / stacktrace-parser

stacktrace-parser

JSON →
library0.1.11jsnpmunverified

stacktrace-parser is a JavaScript library designed to parse stack traces from various JavaScript environments, including web browsers (even older ones like Internet Explorer) and Node.js. It transforms raw stack trace strings into a structured array of objects, where each object represents a line in the stack and contains properties like `lineNumber`, `methodName`, `arguments`, `file`, and `column`. The current stable version is 0.1.11, last published approximately one year ago (as of early 2025). This package appears to be in a maintenance mode, with its low version number and infrequent updates suggesting a stable but not actively developed state, though a TODO list mentions a future v0.3. Its primary differentiator is its broad support for diverse stack trace formats across different JavaScript runtimes, providing a consistent, normalized output for error reporting and debugging tools, including built-in TypeScript type definitions.

npm install stacktrace-parser
INSTALL
IMPORT
SIG · STACKTRACE-PARSER
S
stacktrace-parser
testingjavascriptv0.1.11
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.

stackTraceParser
import * as stackTraceParser from 'stacktrace-parser';
import stackTraceParser from 'stacktrace-parser';
The library primarily exports its functionality via a namespace object, which is then accessed as `stackTraceParser.parse()`.
stackTraceParser
const stackTraceParser = require('stacktrace-parser');
const { parse } = require('stacktrace-parser');
For CommonJS environments, the module is imported as a single object. The `parse` function is a property of this object.
StackFrame
import type { StackFrame } from 'stacktrace-parser';
The library ships with TypeScript types; `StackFrame` is the type definition for individual parsed stack trace objects.

This quickstart demonstrates how to import and use `stacktrace-parser` to parse an error's stack trace into a structured, readable format.

import { parse } from 'stacktrace-parser'; function performOperation(a: number, b: number): number { if (b === 0) { throw new Error('Division by zero is not allowed. Please provide a non-zero divisor.'); } const result = a / b; console.log(`Operation result: ${result}`); return result; } try { // Intentionally cause an error to generate a stack trace performOperation(10, 0); } catch (ex: any) { console.error('An unexpected error occurred during operation:'); console.error('Error message:', ex.message); console.error('--- Raw Stack Trace ---'); console.error(ex.stack); if (ex.stack) { console.log('\n--- Parsed Stack Trace ---'); const parsedStack = parse(ex.stack); parsedStack.forEach((frame, index) => { console.log(` Frame ${index}:`); console.log(` Method: ${frame.methodName}`); console.log(` File: ${frame.file || 'unknown'}:${frame.lineNumber || '?'}:${frame.column || '?'}`); if (frame.arguments && frame.arguments.length > 0) { console.log(` Args: [${frame.arguments.join(', ')}]`); } }); } else { console.warn('Error object did not contain a stack trace to parse.'); } }
Debug
Known issues
gotchaDespite its claim to support 'every browser even old Internet Explorer', the low version (0.1.11) and infrequent updates (last published approximately one year ago) suggest potential limitations or unhandled edge cases with very modern JavaScript syntax, evolving browser environments, or highly minified/transpiled code, which can alter stack trace formats.
fix
Always test with your target environments. For critical applications, consider more actively maintained alternatives or be prepared to contribute fixes for unsupported formats.
affects: <=0.1.11
gotchaThe library is primarily designed for JavaScript stack traces. While a TODO item in the README mentions parsing 'other sources (Ruby, etc.)' for a future v0.3, the current version (0.1.11) is not guaranteed to correctly parse non-JavaScript or highly unconventional stack trace formats, which may lead to incorrect or incomplete output.
fix
Ensure the input to `parse()` is a standard JavaScript error stack string. For non-JS stack traces, use a parser specifically designed for that language/runtime.
affects: <=0.1.11
gotchaStack trace parsing, especially with regex-heavy implementations, can be computationally intensive. Repeatedly parsing very large or deeply nested stack traces in performance-critical loops may introduce noticeable overhead.
fix
Cache parsed stack traces where feasible, and avoid parsing the same stack trace multiple times. Profile your application to identify performance bottlenecks if frequent parsing is necessary.
affects: *
deprecatedThe `engines.node` field specifies `>=6`, which is an extremely old Node.js version. While the library might still function, it has not been explicitly updated or tested against modern Node.js environments (e.g., Node.js 16+), potentially leading to subtle compatibility issues or unexpected behaviors with newer V8 stack trace formats.
fix
Consider testing the library thoroughly in your specific Node.js version. For new projects, evaluating more recently updated stack trace parsers might be prudent.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: stackTraceParser.parse is not a function
Attempting to call `parse` as a direct property of the imported module when it's part of a namespace object, or incorrect CommonJS destructuring.
fix
Ensure you are using the correct import pattern: `import * as stackTraceParser from 'stacktrace-parser';` then call `stackTraceParser.parse(ex.stack);` for ESM, or `const stackTraceParser = require('stacktrace-parser');` then `stackTraceParser.parse(ex.stack);` for CommonJS.
TypeError: Cannot read properties of undefined (reading 'stack')
An error object (or other object passed as `ex`) was `null` or `undefined`, or did not have a `stack` property, before being passed to the parser.
fix
Always validate the error object and its `stack` property before parsing: `if (ex && ex.stack) { const parsed = parse(ex.stack); }`
The 'source' argument must be of type string or an instance of Buffer or Uint8Array. Received type undefined
The `ex.stack` property was `undefined` or `null`, and this non-string value was passed directly to the `parse` function.
fix
Ensure that `ex.stack` is a valid string before passing it to the `parse` function. Add a type check: `if (typeof ex.stack === 'string') { parse(ex.stack); }`
Upgrade
Version history
0.1.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Resources
stacktrace-parser — npm install stacktrace-parser · libregistry