{"id":10797,"library":"error-polyfill","title":"Error Polyfill for V8 Stack Trace API","description":"The `error-polyfill` package provides a polyfill for the V8 Stack Trace API, enabling functionalities like `Error.captureStackTrace` and `Error.prepareStackTrace` in non-V8 JavaScript environments. It aims to standardize how stack traces are generated and accessed across various engines and browsers, including older versions of Node.js, Chrome, Firefox, Internet Explorer, and PhantomJS. The current stable version is 0.1.3, suggesting an early stage of development and a lack of recent updates. A key differentiator is the `Error.getStackTrace` utility, which is recommended for reliably accessing formatted stack traces, as direct `throwable.stack` access might be inconsistent or unformatted in polyfilled environments. The library explicitly requires ES5 support to function.","status":"abandoned","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/inf3rno/error-polyfill","tags":["javascript","error","stack trace","polyfill","v8","Error.captureStackTrace","Error.prepareStackTrace","stack"],"install":[{"cmd":"npm install error-polyfill","lang":"bash","label":"npm"},{"cmd":"yarn add error-polyfill","lang":"bash","label":"yarn"},{"cmd":"pnpm add error-polyfill","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used at runtime to test for ES5 feature compatibility.","package":"capability","optional":false},{"reason":"Used for creating class structures within the polyfill.","package":"o3","optional":false},{"reason":"Provides utility functions utilized by the library.","package":"u3","optional":false}],"imports":[{"note":"The package is designed to be loaded as a CommonJS module for its side effects, polyfilling global `Error` object methods. Direct ES module import syntax (`import 'error-polyfill';`) is not officially supported and may not work as expected given the package's age and design.","wrong":"import 'error-polyfill';","symbol":"error-polyfill","correct":"require(\"error-polyfill\");"},{"note":"This is a static method added to the global `Error` constructor by the polyfill; it's not available on `Error` instances directly.","wrong":"new Error().captureStackTrace(this, this.constructor);","symbol":"Error.captureStackTrace","correct":"Error.captureStackTrace(this, this.constructor);"},{"note":"This static method is the recommended way to retrieve a formatted stack trace from an error instance when the polyfill is active, especially in non-V8 environments. Directly accessing `error.stack` might return an unformatted or inconsistent string.","wrong":"error.stack;","symbol":"Error.getStackTrace","correct":"Error.getStackTrace(error);"}],"quickstart":{"code":"require(\"error-polyfill\");\n\n// Define a custom error to demonstrate captureStackTrace\nvar CustomError = function (message) {\n    this.name = \"CustomError\";\n    this.message = message;\n    // Capture the current stack trace, excluding the CustomError constructor call\n    Error.captureStackTrace(this, this.constructor);\n};\n// Inherit from Error.prototype to ensure proper error instance behavior\nCustomError.prototype = Object.create(Error.prototype);\nCustomError.prototype.constructor = CustomError; // Maintain correct constructor reference\n\nfunction doSomethingWithError() {\n    function triggerError() {\n        throw new CustomError(\"An intentional error occurred!\");\n    }\n    triggerError();\n}\n\ntry {\n    doSomethingWithError();\n} catch (error) {\n    console.log(\"Caught an error:\");\n    if (error instanceof CustomError) {\n        console.log(`  Type: ${error.name}`);\n        console.log(`  Message: ${error.message}`);\n    }\n    // Always use Error.getStackTrace for consistent results with this polyfill\n    console.log(\"  Stack Trace:\\n\" + Error.getStackTrace(error));\n}\n\n// Example of capturing a stack without throwing an error\nconst myObject = {};\nError.captureStackTrace(myObject);\nconsole.log('\\nCaptured stack for a plain object:\\n' + Error.getStackTrace(myObject));","lang":"javascript","description":"This quickstart demonstrates how to load the `error-polyfill`, define a custom error using the polyfilled `Error.captureStackTrace` for structured stack tracing, and then retrieve the formatted stack trace using the recommended `Error.getStackTrace` in both error handling and for general stack capture scenarios."},"warnings":[{"fix":"Ensure the JavaScript execution environment fully supports ES5. For older browsers, this might necessitate transpiling your code to ES5, though this polyfill targets older runtimes where native ES5 support was expected or could be shimmed separately.","message":"The `error-polyfill` library explicitly requires ES5 support to function. Running in environments that do not fully support ES5 will cause the library to throw an error and stop working.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always use the static method `Error.getStackTrace(throwable)` provided by the polyfill to reliably retrieve properly formatted stack traces from `Error` (or `Object`) instances.","message":"When `error-polyfill` is active, especially in non-V8 environments, directly accessing `throwable.stack` may yield unformatted or inconsistent stack trace strings. The polyfill mechanism involves parsing and reformatting the stack.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For new projects, consider using native `Error.stack` if your target environments support it, or opt for a more actively maintained polyfill or transpilation solution for consistent stack trace management. Avoid `error-polyfill` in environments that are not explicitly the deprecated ones it targets.","message":"This package is effectively abandoned, indicated by its very low version (0.1.3), reliance on outdated compatibility targets (Node.js 8/9, PhantomJS 2.1, old browser versions), and use of an inactive CI platform (Travis CI). It is unlikely to function correctly or integrate seamlessly with modern JavaScript runtimes (e.g., Node.js 16+), contemporary browser environments, or modern bundlers (Webpack 5+, Vite) without significant manual polyfilling, configuration, or potential conflicts.","severity":"breaking","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your execution environment (browser, Node.js version) provides complete ES5 support. For very old or non-compliant environments, pre-process your code with a transpiler (e.g., Babel) to ensure ES5 compatibility.","cause":"The runtime environment where the polyfill is executed lacks full ES5 feature support, which is a hard requirement for the library.","error":"Error: ES5 support is required!"},{"fix":"Ensure `require(\"error-polyfill\");` is placed at the very top of your application's main entry file or explicitly before any code that attempts to use the polyfilled `Error` methods.","cause":"The `error-polyfill` library, which adds `captureStackTrace` as a static method to the global `Error` object, was not loaded or executed before code attempted to call `Error.captureStackTrace`.","error":"TypeError: Error.captureStackTrace is not a function"}],"ecosystem":"npm"}