babel-plugin-console

raw JSON →
0.2.1 verified Sat Apr 25 auth: no javascript

A Babel plugin that adds build-time console helper functions to automatically log function parameters, variables, return values, and parent scope — eliminating manual console.log debugging. Current stable version is 0.2.1, released as a series of patches since 2017. Key differentiator: it requires no runtime changes, works with babel-plugin-macros, and supports both browser and Node environments. Unlike manual logging, it provides structured scope inspection at build time, reducing clutter and context loss.

error Plugin/Macro not found: 'console'
cause Missing or incorrect Babel plugin configuration.
fix
Ensure babel-plugin-console is installed and listed in plugins as 'console'.
error Cannot find module 'babel-plugin-console/scope.macro'
cause Macro import path is wrong or babel-plugin-macros not installed.
fix
Install babel-plugin-macros and use exact import path 'babel-plugin-console/scope.macro'.
error console.scope is not a function
cause Plugin not applied before runtime execution or Babel not configured.
fix
Run code through Babel with the plugin enabled.
gotcha console.scope does not log anything in Node for groupCollapse/groupEnd; use plugin version >=0.2.0 for better Node support.
fix Upgrade to 0.2.0+.
gotcha Macro import path uses 'babel-plugin-console/scope.macro', not default export. Common mistake is importing from the package root.
fix Use import scope from 'babel-plugin-console/scope.macro'.
breaking In v0.1.2, import/require statements are removed from the script scope. If you relied on them being logged, they will no longer appear.
fix Move variable declarations instead of imports for logging purposes.
deprecated The package is maintained but low activity. No known deprecations, but consider alternatives like babel-plugin-trace if more features are needed.
fix No action required.
npm install babel-plugin-console
yarn add babel-plugin-console
pnpm add babel-plugin-console

Demonstrates basic plugin setup and using console.scope to log function scope details.

// Install: npm install --save-dev babel-plugin-console
// .babelrc:
{
  "plugins": ["console"]
}

// Source code:
function greet(name) {
  const greeting = 'Hello';
  console.scope('Greeting function');
  return greeting + ' ' + name;
}

greet('World');

// After Babel transform, output logs:
// [console.scope] Greeting function
// [console.scope] name: World
// [console.scope] greeting: Hello
// [console.scope] return: Hello World