Fig. 1
Every engine, one frame shape
V8 in Node, Chrome, Deno and Edge, SpiderMonkey in Firefox, JavaScriptCore in Safari and Bun. The format is detected from the text, so a Safari trace parses fine on your Node server.
Plate I
No. 0.1.0v0.1.0 is out, with zero dependenciesstacktern turns error.stack text from V8, SpiderMonkey and JavaScriptCore into clean, typed frames. Async, eval, native and WebAssembly frames included. Print them back or apply source maps, all in 4.6 kB.
npm i stacktern
{ c.done ? T.copied : '' }
Field sample collected from error.stack
{ heroSamples[h.k].engine }stamp another engine
Observed habitats:
Plate II
Playground
Pick a sample from any engine, paste your own trace or capture one from this browser. The page runs the same code you install from npm.
Point at a label to find its line in the sample.
{ result(p.input, p.rt).frames.length } frames, { result(p.input, p.rt).ms } ms
No frames yet
Paste a stack trace or pick a sample to see its frames here.
Everything runs locally in your browser. Nothing you paste leaves this page.
Plate III
Features
Real stacks are messy: async hops, eval code, builtins, Windows paths and bundler URLs. stacktern reads all of them and tells you what each frame is.
Fig. 1
V8 in Node, Chrome, Deno and Edge, SpiderMonkey in Firefox, JavaScriptCore in Safari and Bun. The format is detected from the text, so a Safari trace parses fine on your Node server.
Fig. 2
Code from eval and new Function keeps the full chain of where it was created, even eval inside eval.
Fig. 3
Spaces and parentheses in paths, ports and query strings, webpack, blob, data and node: URLs, WebAssembly offsets.
Fig. 4
format turns frames back into stack text for V8, SpiderMonkey or JavaScriptCore. Try it:
Fig. 5
mapFrames takes any resolver, and createSourceMapResolver reads v3 maps, including index maps with sections. No extra package.
Fig. 6
No dependencies, ESM and CommonJS builds, hand written TypeScript types.
Plate IV
Quick start
Pass an Error or a string. You get an array of plain objects with the same fields for every engine.
import { parse } from 'stacktern';
try {
await loadConfig();
} catch (error) {
for (const frame of parse(error)) {
console.log(frame.functionName, frame.fileName, frame.lineNumber);
}
}
// Strings work too, from any engine:
parse('load@https://app.dev/main.js:12:5');
// [{ functionName: 'load', fileName: 'https://app.dev/main.js',
// lineNumber: 12, columnNumber: 5, isNative: false, ... }]import { parse, format } from 'stacktern';
const frames = parse(firefoxStack);
// Print the same frames the way V8 would.
console.log(format(frames, { runtime: 'v8' }));
// at load (https://app.dev/main.js:12:5)
// at async boot (https://app.dev/main.js:40:3)import { parse, mapFrames, createSourceMapResolver } from 'stacktern';
const map = JSON.parse(await readFile('dist/app.js.map', 'utf8'));
const resolve = createSourceMapResolver(map);
const frames = mapFrames(parse(error), (frame) =>
frame.fileName.endsWith('/app.js') ? resolve(frame) : null,
);
// frames[0].fileName is now 'src/app.ts', with the original line and columnconst { parse, parseFrame } = require('stacktern');
parseFrame(' at new Store (C:\\app (copy)\\store.js:3:9)');
// { functionName: 'Store', isConstructor: true,
// fileName: 'C:\\app (copy)\\store.js', lineNumber: 3, columnNumber: 9, ... }Plate V
Benchmarks
Measured on the same corpus of 71 real and documented stacks, with error-stack-parser and stacktrace-parser installed side by side.
Operations per second, higher is better. Median of 7 runs on Node 24.16.0, Windows 10, Ryzen 7 7800X3D.
Share of frame fields that match the expected frames, over 44 stacks and 200 frames.
Fig. 9 Source map lookups
| Feature | stacktern | error-stack-parser 2.1.4 | stacktrace-parser 0.1.11 |
|---|---|---|---|
| V8, SpiderMonkey and JavaScriptCore formats | yes | yes | yes |
| Flags for async, native, eval and new frames | yes | no | no |
| Keeps builtin frames such as Promise.all | yes | no | partial |
| Paths with parentheses | yes | no | yes |
| WebAssembly frames with positions | yes | partial | no |
| Eval origin chain | yes | no | no |
| Prints stacks back | yes | no | no |
| Source map resolver | yes | no | no |
| TypeScript types | yes | yes | yes |
| Runtime dependencies | 0 | 1 | 1 |
Checked by running each package on the same inputs, see bench/accuracy.mjs in the repository.
Plate VI
Size and support
Minified with Bun, compressed with zlib. Import only parse and parseFrame and your bundler drops the rest.
Plate VII
FAQ
Short answers to what people ask first. The README has the details.
Yes. The format is detected from the text, not from the runtime the code runs in.
That is what V8 prints and what its CallSite API reports. The place where eval was called is in evalOrigin.
No, it parses one stack at a time. Call parse on each error you care about.
It only exists in V8, only for errors created in the same process, and only if the hook is installed before the stack is formatted. stacktern works on the text you already have.
They are skipped. The message line, blank lines and prose never become frames, and parse never throws on odd input.
Yes. Scanning is linear, nesting is capped, and there are no regular expressions that can backtrack badly. See SECURITY.md.
Install it in a second, parse stacks from any engine, and keep your crash reports readable.