Callsites is a low-level utility that retrieves an array of V8 CallSite objects from the current JavaScript stack trace. It provides direct access to the V8 stack trace API, allowing developers to inspect intricate details of each call in the stack, such as file names, line numbers, column numbers, function names, and execution context. This package is currently stable at version 4.2.0 and maintains an active release cadence, with recent updates adding Bun support and refining TypeScript definitions. It is a pure ESM package since v4.0.0, making it suitable for modern Node.js environments. Its primary differentiator is providing raw, unopinionated access to V8's callsite information, empowering advanced debugging, logging, and error reporting scenarios.
npm install callsitesVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `callsites` to retrieve the filename of the function that called the immediate parent function in the stack trace.
Migrate your project to use ES Modules (`type: "module"` in `package.json` or `.mjs` files), or dynamically import `callsites` using `import()` if you must remain in CJS. For example: `const callsites = await import('callsites');`Ensure your Node.js environment is version 12.20 or newer. You can use tools like `nvm` or Docker to manage Node.js versions.
Always use the provided `get*` methods on the `CallSite` objects (e.g., `callsite.getFileName()`) instead of trying to access properties directly (e.g., `callsite.fileName`). Refer to the V8 Stack Trace API documentation for available methods.
Do not solely rely on function name inference for critical logic. Combine with other identifiers like `getFileName()` and `getLineNumber()` for more robust stack analysis. Consider providing named functions where possible.
Either convert your project or the specific file to an ES Module (by adding `"type": "module"` to your `package.json` or changing the file extension to `.mjs`), or use dynamic `import()`: `const callsites = await import('callsites');`Since v4.0.0, `callsites` is pure ESM and should be imported using `import callsites from 'callsites';`. If you *must* use CommonJS, use dynamic import: `const callsitesPromise = import('callsites'); callsitesPromise.then(mod => mod.default());`Ensure the object you're interacting with is indeed a `CallSite` instance from the `callsites()` array, and always use the method syntax, e.g., `callsite.getFileName()`.
No dependency data recorded yet.