Registry / serialization / babel-errors

babel-errors

JSON →
library1.1.1jsnpmunverified

A library for creating nicer error messages with code frames for Babel transformations and plugins. Current stable version 1.1.1 provides utilities like buildCodeFrameError, prettyError, wrapErrorWithCodeFrame, and createErrorWithLoc. Sporadically maintained, it differentiates from Babel's built-in error formatting by offering explicit functions to construct location-aware errors outside the plugin context.

npm install babel-errors
INSTALL
IMPORT
SIG · BABEL-ERRORS
B
babel-errors
serializationjavascriptv1.1.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BabelError
✓ import { BabelError } from 'babel-errors'
✗ import BabelError from 'babel-errors'
Named export, not default.
prettyError
✓ import { prettyError } from 'babel-errors'
✗ const prettyError = require('babel-errors').prettyError
Named export, prefer ESM.
buildCodeFrameError
✓ import { buildCodeFrameError } from 'babel-errors'
✗ import buildCodeFrameError from 'babel-errors/buildCodeFrameError'
Named export from package root, no subpath.

Demonstrates creating errors with location and building code frame errors using babel-errors with a simple AST.

import { buildCodeFrameError, createErrorWithLoc } from 'babel-errors'; import { parse } from '@babel/parser'; import generate from '@babel/generator'; const code = 'const x = 1;'; const ast = parse(code, { sourceType: 'module' }); const { path } = ast; // Throw an error with location const line = 1, column = 6; const err = createErrorWithLoc('Test error at position', line, column); console.log(err.message); console.log('Name:', err.name); // BabelError // Use buildCodeFrameError with a path try { buildCodeFrameError(path, 'Error with this Path'); } catch (e) { console.log(e.message); }
Debug
Known issues
gotchabuildCodeFrameError requires a Babel NodePath object; passing a plain object will throw without clear error.
fix
Ensure argument is a valid Babel Path (e.g., from traversal).
affects: <=1.1.1
deprecatedFunction toErrorStack is deprecated; use error.stack or custom formatting instead.
fix
Use error.stack or manual format.
affects: >=1.0.0
gotchawrapErrorWithCodeFrame only adds code frame if the error has line/column properties; otherwise returns original error silently.
fix
Ensure error has loc property (use createErrorWithLoc).
affects: <=1.1.1
Errors
Common errors & fixes
Error: Cannot find module 'babel-code-frame'
Missing peer dependency babel-code-frame.
fix
Run npm install babel-code-frame.
TypeError: path.buildCodeFrameError is not a function
Trying to use babel-errors' buildCodeFrameError as a method on a Path object.
fix
Call buildCodeFrameError(path, message) as a standalone function.
Uncaught TypeError: createErrorWithLoc is not a function
Importing as default instead of named export.
fix
Use import { createErrorWithLoc } from 'babel-errors'.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
babel-code-framerequiredrequired to generate code frame string in errors
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
babel-errors — npm install babel-errors · libregistry