youch-core is a specialized JavaScript/TypeScript library designed to parse `Error` instances into a structured collection of detailed stack frames. It functions as the core error parsing engine utilized by the `youch` package, which is responsible for rendering user-friendly error pages in web applications and formatted output in terminal environments. This library is considered low-level, intended for developers who need to build custom error display solutions while leveraging `youch-core`'s robust error introspection capabilities, rather than being a direct-use package for most applications. It provides granular information for each stack frame, including the filename, line number, column number, and a snippet of the relevant source code, along with flags indicating if a frame is related to `node_modules` or is a native function. The current stable version is `0.3.3`, reflecting an active development cadence with several minor releases and dependency updates throughout the past year, indicating ongoing maintenance and improvement. A significant feature is its support for custom source code loaders, enabling integration into diverse JavaScript runtime environments like Deno or Bun where standard Node.js `fs` module access might be unavailable or unsuitable for retrieving source files. It explicitly targets and supports modern Node.js versions (v18 and newer) and includes comprehensive TypeScript type definitions, ensuring a smooth and type-safe development experience for TypeScript users building custom error handling utilities.
npm install youch-coreVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a JavaScript error into structured stack frames, including mocking a custom source loader for illustrative purposes and logging key frame details.
Remove any references to `error.metadata`. This property is now managed by the higher-level `youch` package for HTML rendering and is no longer part of `youch-core`'s output.
Update existing custom source loaders. The `defineSourceLoader` method now expects a callback that accepts a `StackFrame` object as its sole argument, providing more contextual information. Refer to the current documentation or TypeScript types for the updated signature.
Ensure your Node.js runtime environment is version 18 or later. Running `youch-core` on older Node.js versions may lead to compatibility issues or errors related to unsupported syntax or APIs.
Use ES module import syntax: `import { ErrorParser } from 'youch-core'`. Ensure your project is configured for ES Modules (e.g., by adding `"type": "module"` to your `package.json` or using `.mjs` file extensions).Always use `await` when calling `parser.parse(error)`. For example: `const parsedError = await parser.parse(error)` within an `async` function.
Check if `frame.source` exists before accessing it (`if (frame.source) { ... }`). Also, ensure your custom `defineSourceLoader` implementation correctly populates the `frame.source` array for relevant frames.No dependency data recorded yet.