Beautiful, Rust-style error reporting for Node.js
Transform noisy Node.js stack traces into beautiful, actionable error reports with source code context—just like Rust, Next.js, and other modern frameworks.
- Zero Configuration: Just import and errors become beautiful
- Source Code Context: See the exact line that caused the error with surrounding code
- Syntax Highlighting: Code snippets are colorized for readability
- Source Map Support: Works with TypeScript and transpiled code
- Smart Filtering: Focuses on your code, not
node_modules - Zero Runtime Cost: Only activates when errors are thrown
- Graceful Fallback: Never crashes your app—falls back to standard traces if needed
Before (Standard Node.js):
TypeError: Cannot read properties of undefined (reading 'name')
at getUser (/app/src/services/user.ts:45:12)
at processRequest (/app/src/handlers/api.ts:23:8)
at /app/src/index.ts:67:5
After (error-less):
TypeError: Cannot read properties of undefined (reading 'name')
→ ./src/services/user.ts:45:12
43 │ function getUser(id: string) {
44 │ const user = users.get(id);
> 45 │ return user.name;
│ ^^^
46 │ }
47 │
tip: Verify the value type matches what the operation expects
npm install error-lessJust import at the top of your entry file:
import 'error-less/register';
// Your code here...
throw new Error('Something went wrong!');For more control:
import { install, configure } from 'error-less';
install({
showFullStack: true,
contextLinesBefore: 3,
contextLinesAfter: 3,
});import { formatError } from 'error-less';
try {
riskyOperation();
} catch (error) {
console.error(formatError(error));
// Handle the error...
}import { install } from 'error-less';
install({
// Lines of context before the error line (default: 2)
contextLinesBefore: 2,
// Lines of context after the error line (default: 2)
contextLinesAfter: 2,
// Enable source map resolution (default: true)
enableSourceMaps: true,
// Filter out node_modules frames (default: true)
filterNodeModules: true,
// Show full stack trace after code frame (default: false)
showFullStack: false,
// Force colors on/off (default: auto-detected)
colors: true,
// Custom frame filter
frameFilter: (frame) => !frame.filePath.includes('test'),
});Installs the custom stack trace handler.
Restores the original stack trace behavior.
Updates configuration without reinstalling.
Returns a formatted error string. Useful for try/catch blocks.
Formats any thrown value (not just Error instances).
Returns whether error-less is currently active.
Get parsed stack frames for advanced usage.
Clear the file content cache.
Clear the source map consumer cache.
error-less is written in TypeScript and provides full type definitions.
import type { ErrorLessConfig, ParsedFrame } from 'error-less';error-less automatically detects and uses source maps:
- Inline source maps: Embedded in the compiled file as base64
- External source maps:
.mapfiles alongside compiled files - Embedded source content: Uses
sourcesContentfrom maps when available
For TypeScript, ensure your tsconfig.json includes:
{
"compilerOptions": {
"sourceMap": true
}
}error-less hooks into V8's Error.prepareStackTrace API. When an error's .stack property is accessed:
- The custom handler receives structured stack frame data
- Frames are parsed to extract file paths, line numbers, and columns
- Source maps are checked for original source locations
- Source files are read and code context is extracted
- A beautiful, syntax-highlighted output is generated
This approach has zero performance impact during normal execution—code only runs when an error is thrown and its stack is accessed.
| Feature | error-less | pretty-error | youch |
|---|---|---|---|
| Zero config | ✅ | ❌ | ❌ |
| Source code display | ✅ | ❌ | ✅ |
| Source map support | ✅ | ❌ | ✅ |
| Syntax highlighting | ✅ | ❌ | ❌ |
| Smart filtering | ✅ | ✅ | ✅ |
| Pure terminal output | ✅ | ✅ | ❌ (HTML) |
MIT