stacktrace.js is a framework-agnostic micro-library designed to generate, parse, and enhance JavaScript stack traces across all environments, including browsers and Node.js. The current stable version is 2.0.2. It maintains a moderate release cadence, with updates typically addressing dependency bumps, bug fixes, and minor enhancements. Key differentiators include its ability to parse ES6 code, extensible StackFrame objects that report on constructor, native, or eval code, and its use of source maps for enhanced trace accuracy. It modularizes functionality into several sub-projects like error-stack-parser and stacktrace-gps to handle specific aspects of stack trace processing, providing both asynchronous (Promise-based) and synchronous API methods for flexibility. The library is particularly useful for robust error reporting and debugging applications.
npm install stacktrace-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates asynchronous stack trace capture from a new Error object and the current execution context, as well as a synchronous trace.
Consult the official StackFrame documentation or the v2.0.0 release notes for details on new properties and updated usage. Generally, relying on `sf.toString()` or accessing public properties like `fileName`, `lineNumber` is safer.
For enhanced stack traces with source map resolution and better readability, always prefer the asynchronous `StackTrace.get()` or `StackTrace.fromError()` methods, which return Promises. Use `getSync()` only when strict synchronous behavior is absolutely required and less detail is acceptable.
Review the MIT License to ensure compliance. If your project has strict licensing requirements, confirm that the MIT License is compatible with your project's legal framework.
Refer to the '0.x -> 1.x Migration Guide' (linked in the README) for detailed instructions on adapting your codebase to the new modularized API. This primarily involves importing `StackTrace` and its methods directly, rather than relying on a single global object with all functionalities.
Use `StackTrace.get().then(...)` for asynchronous, Promise-based operations, or directly process the Array returned by `StackTrace.getSync()`.
Ensure you have `import * as StackTrace from 'stacktrace-js';` or `import { get, fromError } from 'stacktrace-js';` at the top of your ES module, or that the UMD bundle has been correctly loaded in a non-module environment.Ensure the `Error` object passed to `StackTrace.fromError()` is a standard JavaScript Error instance. If the issue persists, it might indicate an environment-specific parsing limitation; consider reporting to the library's GitHub issues.