{"id":18989,"library":"babel-errors","title":"babel-errors","description":"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.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install babel-errors","lang":"bash","label":"npm"},{"cmd":"yarn add babel-errors","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-errors","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"required to generate code frame string in errors","package":"babel-code-frame","optional":false}],"imports":[{"note":"Named export, not default.","wrong":"import BabelError from 'babel-errors'","symbol":"BabelError","correct":"import { BabelError } from 'babel-errors'"},{"note":"Named export, prefer ESM.","wrong":"const prettyError = require('babel-errors').prettyError","symbol":"prettyError","correct":"import { prettyError } from 'babel-errors'"},{"note":"Named export from package root, no subpath.","wrong":"import buildCodeFrameError from 'babel-errors/buildCodeFrameError'","symbol":"buildCodeFrameError","correct":"import { buildCodeFrameError } from 'babel-errors'"}],"quickstart":{"code":"import { buildCodeFrameError, createErrorWithLoc } from 'babel-errors';\nimport { parse } from '@babel/parser';\nimport generate from '@babel/generator';\n\nconst code = 'const x = 1;';\nconst ast = parse(code, { sourceType: 'module' });\nconst { path } = ast;\n\n// Throw an error with location\nconst line = 1, column = 6;\nconst err = createErrorWithLoc('Test error at position', line, column);\nconsole.log(err.message);\nconsole.log('Name:', err.name); // BabelError\n\n// Use buildCodeFrameError with a path\ntry {\n  buildCodeFrameError(path, 'Error with this Path');\n} catch (e) {\n  console.log(e.message);\n}","lang":"javascript","description":"Demonstrates creating errors with location and building code frame errors using babel-errors with a simple AST."},"warnings":[{"fix":"Ensure argument is a valid Babel Path (e.g., from traversal).","message":"buildCodeFrameError requires a Babel NodePath object; passing a plain object will throw without clear error.","severity":"gotcha","affected_versions":"<=1.1.1"},{"fix":"Use error.stack or manual format.","message":"Function toErrorStack is deprecated; use error.stack or custom formatting instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure error has loc property (use createErrorWithLoc).","message":"wrapErrorWithCodeFrame only adds code frame if the error has line/column properties; otherwise returns original error silently.","severity":"gotcha","affected_versions":"<=1.1.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install babel-code-frame.","cause":"Missing peer dependency babel-code-frame.","error":"Error: Cannot find module 'babel-code-frame'"},{"fix":"Call buildCodeFrameError(path, message) as a standalone function.","cause":"Trying to use babel-errors' buildCodeFrameError as a method on a Path object.","error":"TypeError: path.buildCodeFrameError is not a function"},{"fix":"Use import { createErrorWithLoc } from 'babel-errors'.","cause":"Importing as default instead of named export.","error":"Uncaught TypeError: createErrorWithLoc is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}