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
muslnode 18–226 runs
build_error
glibcnode 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);
}
Errors
Common errors & fixes
Error: Cannot find module 'babel-code-frame'
Missing peer dependency babel-code-frame.
fixRun 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.
fixCall buildCodeFrameError(path, message) as a standalone function.
Uncaught TypeError: createErrorWithLoc is not a function
Importing as default instead of named export.
fixUse import { createErrorWithLoc } from 'babel-errors'. Audit
Dependencies
babel-code-framerequiredrequired to generate code frame string in errors