babel-log
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
babel-log is a lightweight utility for logging Babel AST paths and nodes with clean, colored formatting in the console. As of version 2.0.0, it provides a single default-exported function that accepts any object, making it ideal for debugging Babel plugins. It is in active development with a low release cadence. Unlike manual console.log, babel-log formats complex AST structures for readability.
Common errors
error TypeError: log is not a function ↓
cause Importing with named import instead of default import.
fix
Use import log from 'babel-log' (without curly braces).
error Cannot find module 'babel-log' ↓
cause Package not installed in project dependencies.
fix
Run npm install babel-log --save-dev
Warnings
gotcha The function only logs to console and returns undefined; it is not for serialization. ↓
fix Use it only for debugging; do not rely on return value.
Install
npm install babel-log yarn add babel-log pnpm add babel-log Imports
- default wrong
import { log } from 'babel-log'correctimport log from 'babel-log' - default wrong
const { log } = require('babel-log')correctconst log = require('babel-log') - log (type)
import type log from 'babel-log'
Quickstart
import log from 'babel-log';
export default function myBabelPlugin() {
return {
visitor: {
Identifier(path) {
log(path.node); // logs the node with pretty formatting
}
}
};
}