stack-chain is a utility library for Node.js that provides an API to intercept, modify, and reformat V8 JavaScript engine's stack traces. It allows developers to programmatically extend, filter, and replace the default stack trace formatting behavior of `Error.stack`. This is particularly useful for tools that need to clean up stack traces (e.g., hide internal frames in frameworks), provide custom error reporting, or integrate with debugging utilities. The current stable version is 2.0.0. The project appears to be abandoned, with the last publish over 8 years ago and last commit in 2017. This means it may not be compatible with newer Node.js versions or modern JavaScript features like ESM, and new releases or bug fixes are highly unlikely. Its key differentiator was offering a centralized, hook-based system for manipulating global `Error.stack` behavior.
npm install stack-chainVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to attach a stack frame filter and replace the global stack trace formatter, then trigger and print an error.
Thoroughly test `stack-chain` in your environment, especially if other global error handlers or debugging tools are in use. Consider encapsulating its use or only enabling it in specific execution contexts.
Be aware of the caching behavior of V8 `Error` objects. If you need to ensure a restored format, primarily apply `restore()` before new errors are generated or before their stacks are accessed.
For new projects or existing projects on recent Node.js versions, consider alternative, actively maintained stack manipulation libraries or native V8 APIs directly. If using this package, thorough compatibility testing with your specific Node.js version is essential.
Always ensure your modifier function for `attach` methods explicitly returns an array of `callSite` objects, even if it's the original, unmodified array.
Review your `modifier` functions. Ensure they always return an array, and that array contains valid `CallSite` objects. Do not mutate `CallSite` objects in ways that remove essential properties if they are expected by subsequent processors.
Verify that `stack-chain` is the last or only library modifying `Error.stack` at the global level. Ensure `chain.format.replace` is called early in your application's lifecycle, before `Error.stack` is likely to be accessed for the first time on relevant error objects.
Convert your module to CommonJS by using `.js` extension with `"type": "commonjs"` in `package.json`, or rename your file to `.cjs`. Alternatively, if you must use ESM, you can try dynamic `import('stack-chain')` or a build step to transpile, but direct compatibility is not guaranteed for an abandoned package.No dependency data recorded yet.