babel-plugin-captains-log

raw JSON →
1.3.2 verified Sat Apr 25 auth: no javascript maintenance

A Babel plugin (v1.3.2, last updated July 2020, no recent releases) that automatically injects file name, line/column position, and variable name labels into console.log and other console method calls. Unlike manual logging wrappers, it works at the AST level during build time, supports ignore patterns, custom logger names, and selective method targeting. Requires Babel v6, ESM/CJS compatible, used as a development transform to enhance debugging output in bundled code.

error Error: Cannot find module 'babel-plugin-captains-log'
cause Plugin not installed or Babel not configured to resolve node_modules
fix
npm install --save-dev babel-plugin-captains-log
error SyntaxError: Unexpected token (3:0)
cause Plugin transforms code but Babel version does not support the output syntax (e.g., arrow functions in older environments)
fix
Ensure Babel presets or plugins (e.g., @babel/preset-env) are configured to transpile the output.
error TypeError: Cannot read property 'scope' of undefined
cause Using plugin with Babel 7 which has different visitor API
fix
Upgrade to a Babel 7 compatible plugin or downgrade to Babel 6.
breaking Requires Babel v6, not v7+
fix Use @babel/plugin prefix or consider alternatives for Babel 7, e.g., babel-plugin-transform-console-log or custom build.
gotcha Plugin mutates console statements globally; logged variable name may show original variable name even after minification if source maps enabled
fix Disable injectVariableName in production build or use plugin only in development mode.
deprecated No updates since July 2020; repository may be unmaintained
fix Consider actively maintained alternatives like babel-plugin-transform-console-log, or fork the repository.
npm install babel-plugin-captains-log
yarn add babel-plugin-captains-log
pnpm add babel-plugin-captains-log

Demonstrates plugin setup in .babelrc, default transformation adding file location and variable name, and all available options.

// .babelrc
{
  "plugins": ["babel-plugin-captains-log"]
}

// Before transformation
let x = 5;
console.log(x);

// After transformation (output during development)
let x = 5;
console.log("input.js(3:0)", "x", x);

// With options
{
  "plugins": [
    ["babel-plugin-captains-log", {
      "methods": ["debug", "info"],
      "ignorePatterns": ["node_modules", "*.spec.js"],
      "loggerName": "myLogger",
      "injectVariableName": true,
      "injectFileName": true
    }]
  ]
}