Registry / observability / error-stack-parser

error-stack-parser

JSON →
library2.1.4jsnpmunverified

Error Stack Parser is a lightweight, cross-browser JavaScript library designed to extract structured information from JavaScript `Error` objects' `stack` property. It parses raw stack traces into an array of `StackFrame` objects, each containing details like function name, file URL, line number, and column number. This provides a programmatically accessible representation of the call stack, which is crucial for error reporting and debugging tools. The current stable version is 2.1.4. While a strict release cadence isn't explicitly stated, the project maintains regular updates for bug fixes and dependency management. Its key differentiator is its focus on providing a standardized, structured output (`StackFrame` objects) across various browser and Node.js environments, abstracting away the inconsistencies in native `Error.stack` formats.

npm install error-stack-parser
INSTALL
IMPORT
SIG · ERROR-STACK-PARSER
E
error-stack-parser
observabilityjavascriptv2.1.4
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.

ErrorStackParser
✓ import ErrorStackParser from 'error-stack-parser';
✗ import { ErrorStackParser } from 'error-stack-parser';
While error-stack-parser exports a CommonJS module (`module.exports = ErrorStackParser`), modern bundlers and TypeScript with `esModuleInterop` enabled will allow this default import syntax. Without `esModuleInterop`, you might need `import * as ErrorStackParser from 'error-stack-parser';` or explicit CommonJS `require`.
ErrorStackParser (CommonJS)
✓ const ErrorStackParser = require('error-stack-parser');
For Node.js environments using CommonJS modules.
StackFrame (Type)
✓ import type { StackFrame } from 'error-stack-parser';
✗ import { StackFrame } from 'stackframe';
The `StackFrame` type is re-exported directly from `error-stack-parser` for convenience and backward compatibility since v2.1.0, though its definition originates from the `stackframe` package.

Demonstrates how to catch an error, parse its stack trace using `ErrorStackParser.parse`, and then iterate through the resulting `StackFrame` objects to display detailed information about each call site.

import ErrorStackParser from 'error-stack-parser'; function thirdFunction() { try { throw new Error('This is a test error!'); } catch (error) { if (error instanceof Error) { console.log('Parsing error stack...'); const frames = ErrorStackParser.parse(error); console.log(`Found ${frames.length} stack frames.`); frames.forEach((frame, index) => { console.log(`\n--- Frame ${index + 1} ---`); console.log(`Function: ${frame.functionName || '<anonymous>'}`); console.log(`File: ${frame.fileName || '<unknown>'}:${frame.lineNumber || '?'}:${frame.columnNumber || '?'}`); if (frame.isNative) console.log(' (Native Code)'); if (frame.isEval) console.log(` (Eval Code from ${frame.evalOrigin})`); }); } else { console.error('Caught something that is not an Error object.'); } } } function secondFunction() { thirdFunction(); } function firstFunction() { secondFunction(); } firstFunction();
Debug
Known issues
breakingThe `stackframe` dependency was updated to v1.x, which changed how `StackFrame` objects are constructed and accessed. Code directly interacting with `StackFrame` internals or expecting specific properties/methods from `stackframe` v0.x will break.
fix
Review the `stackframe` CHANGELOG for v1.x (if directly using `stackframe`) and adapt your code to the new `StackFrame` API. If only consuming `StackFrame` objects from `error-stack-parser`, ensure your code correctly accesses their properties (e.g., `fileName`, `lineNumber`).
affects: >=2.0.0
gotchaParsing limitations exist for older browsers. `Error` objects in IE9 and earlier lack sufficient stack information for meaningful parsing. IE10 only provides a `stack` property after an error is explicitly `throw`n.
fix
Be aware of these limitations when targeting legacy browser environments. Consider using a polyfill or alternative error capture mechanism if detailed stack traces are critical in these browsers.
affects: <=1.0.0
gotchaIn v1.3.0, the handling of anonymous functions and 'new Constructor' calls was improved, removing previous attempts to normalize cross-browser representations. While an improvement, this might subtly change the parsed `functionName` for some anonymous functions compared to earlier versions.
fix
Review your error reporting and analytics if they rely on the exact `functionName` output for anonymous functions parsed by versions prior to 1.3.0.
affects: >=1.3.0
Errors
Common errors & fixes
TypeError: ErrorStackParser.parse is not a function
Incorrect import statement (e.g., named import for a default-exported CommonJS module) or attempting to call `parse` directly on the module object without accessing the `ErrorStackParser` class.
fix
Ensure you are importing the `ErrorStackParser` class correctly. For ESM/TypeScript, use `import ErrorStackParser from 'error-stack-parser';`. For CommonJS, use `const ErrorStackParser = require('error-stack-parser');`.
Property 'someOldStackFrameProperty' does not exist on type 'StackFrame'.
Attempting to access properties or methods of `StackFrame` objects that were removed or renamed in `stackframe` v1.x (and thus `error-stack-parser` v2.x).
fix
Consult the `stackframe` v1.x documentation or source to verify the correct property names and methods for `StackFrame` objects. Update your code to use the current API.
Upgrade
Version history
2.1.4latest on npm
Audit
Dependencies
stackframerequiredProvides the structured StackFrame objects that error-stack-parser generates. Updated to v1.x in error-stack-parser v2.0.0.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
3
Resources
error-stack-parser — npm install error-stack-parser · libregistry