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-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use `stacktrace-parser` to parse an error's stack trace into a structured, readable format.
Always test with your target environments. For critical applications, consider more actively maintained alternatives or be prepared to contribute fixes for unsupported formats.
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.
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.
Consider testing the library thoroughly in your specific Node.js version. For new projects, evaluating more recently updated stack trace parsers might be prudent.
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.Always validate the error object and its `stack` property before parsing: `if (ex && ex.stack) { const parsed = parse(ex.stack); }`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); }`No dependency data recorded yet.