{"id":13127,"library":"error-stack-parser","title":"Error Stack Parser","description":"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.","status":"active","version":"2.1.4","language":"javascript","source_language":"en","source_url":"git://github.com/stacktracejs/error-stack-parser","tags":["javascript","stacktrace","error","stack","parser","typescript"],"install":[{"cmd":"npm install error-stack-parser","lang":"bash","label":"npm"},{"cmd":"yarn add error-stack-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add error-stack-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the structured StackFrame objects that error-stack-parser generates. Updated to v1.x in error-stack-parser v2.0.0.","package":"stackframe","optional":false}],"imports":[{"note":"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`.","wrong":"import { ErrorStackParser } from 'error-stack-parser';","symbol":"ErrorStackParser","correct":"import ErrorStackParser from 'error-stack-parser';"},{"note":"For Node.js environments using CommonJS modules.","symbol":"ErrorStackParser (CommonJS)","correct":"const ErrorStackParser = require('error-stack-parser');"},{"note":"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.","wrong":"import { StackFrame } from 'stackframe';","symbol":"StackFrame (Type)","correct":"import type { StackFrame } from 'error-stack-parser';"}],"quickstart":{"code":"import ErrorStackParser from 'error-stack-parser';\n\nfunction thirdFunction() {\n  try {\n    throw new Error('This is a test error!');\n  } catch (error) {\n    if (error instanceof Error) {\n      console.log('Parsing error stack...');\n      const frames = ErrorStackParser.parse(error);\n      console.log(`Found ${frames.length} stack frames.`);\n      frames.forEach((frame, index) => {\n        console.log(`\\n--- Frame ${index + 1} ---`);\n        console.log(`Function: ${frame.functionName || '<anonymous>'}`);\n        console.log(`File: ${frame.fileName || '<unknown>'}:${frame.lineNumber || '?'}:${frame.columnNumber || '?'}`);\n        if (frame.isNative) console.log('  (Native Code)');\n        if (frame.isEval) console.log(`  (Eval Code from ${frame.evalOrigin})`);\n      });\n    } else {\n      console.error('Caught something that is not an Error object.');\n    }\n  }\n}\n\nfunction secondFunction() {\n  thirdFunction();\n}\n\nfunction firstFunction() {\n  secondFunction();\n}\n\nfirstFunction();","lang":"typescript","description":"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."},"warnings":[{"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`).","message":"The `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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Parsing 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.","severity":"gotcha","affected_versions":"<=1.0.0"},{"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.","message":"In 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.","severity":"gotcha","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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');`.","cause":"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.","error":"TypeError: ErrorStackParser.parse is not a function"},{"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.","cause":"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).","error":"Property 'someOldStackFrameProperty' does not exist on type 'StackFrame'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}