{"library":"stacktrace-js","title":"Universal JavaScript Stack Trace Library","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install stacktrace-js"],"cli":null},"imports":["import * as StackTrace from 'stacktrace-js';\n// or\nimport { get, fromError, instrument, getSync, generateArtificially } from 'stacktrace-js';","import { StackFrame } from 'stackframe';","import { fromError } from 'stacktrace-js';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://www.stacktracejs.com","github":"https://github.com/stacktracejs/stacktrace.js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stacktrace-js","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { get, fromError } from 'stacktrace-js';\n\nasync function captureAndLogStackTraces() {\n  try {\n    // Simulate an error to capture its stack\n    let simulatedError = new Error('This is a simulated error for demonstration.');\n    const stackframesFromError = await fromError(simulatedError);\n    console.log('--- Stack trace from Error object ---');\n    console.log(stackframesFromError.map(sf => sf.toString()).join('\\n'));\n\n    // Get the stack trace from the current execution point\n    const stackframesCurrent = await get();\n    console.log('\\n--- Stack trace from current location ---');\n    console.log(stackframesCurrent.map(sf => sf.toString()).join('\\n'));\n\n  } catch (err: any) {\n    console.error('Failed to get stack trace:', err.message);\n  }\n}\n\ncaptureAndLogStackTraces();\n\n// Example of synchronous usage (without source map resolution)\nimport { getSync } from 'stacktrace-js';\nfunction callSynchronousTrace() {\n  console.log('\\n--- Synchronous Stack trace (no source maps) ---');\n  const syncStackframes = getSync();\n  console.log(syncStackframes.map(sf => sf.toString()).join('\\n'));\n}\ncallSynchronousTrace();","lang":"typescript","description":"Demonstrates asynchronous stack trace capture from a new Error object and the current execution context, as well as a synchronous trace.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}