Registry / devops / babel-plugin-js-logger

babel-plugin-js-logger

JSON →
library1.0.17jsnpmunverified

Babel plugin that automatically inserts a logger declaration (via js-logger) at the top of every transpiled JavaScript file, enabling consistent logging across backend and frontend projects. Current stable version: 1.0.17. Maintained as of early 2021, with infrequent updates. Key differentiators: automatic logger instantiation per file, configurable logger name formatting (project/level/separator/extensions), and support for both Babel standalone and Webpack. Alternative to manual logger setup in each file. Note: requires js-logger as a peer dependency and Babel as a build tool.

npm install babel-plugin-js-logger
INSTALL
IMPORT
SIG · BABEL-PLUGIN-JS-LO
B
babel-plugin-js-logger
devopsjavascriptv1.0.17
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
// Add 'js-logger' to .babelrc plugins array: { "plugins": ["js-logger"] }
The plugin is a Babel plugin, not a runtime import. It is configured in .babelrc or babel.config.js.
js-logger
import 'js-logger'; // or const Logger = require('js-logger');
js-logger is a runtime dependency that must be installed separately.
get
const logger = Logger.get('my:name');
const logger = Logger.get('my:name'); // correct usage
The plugin automatically generates these calls per file. The factory option defaults to 'get'.

Installs and configures the plugin, initializes js-logger, and demonstrates automatic logger insertion per file.

// Install: npm install js-logger --save && npm install babel-plugin-js-logger --save-dev // .babelrc { "plugins": ["js-logger"] } // In your main entry point (e.g., main.js) require('js-logger').useDefaults(); // initialize js-logger // All other files will automatically have a logger variable // Example: some/path/file.js // The plugin inserts: const logger = require('js-logger').get('project:some:path:file'); // Use logger logger.info('Hello from file!');
Debug
Known issues
gotchaWith ES modules (import), the plugin's generated logger declaration may execute after imports due to hoisting, causing initialization order issues.
fix
Use a separate init file imported first, e.g., import './logger-init.js'; (see README).
affects: *
gotchaThe plugin automatically inserts a require() for js-logger even if it's not used, potentially causing tree-shaking to fail.
fix
Consider using manual logger setup if tree-shaking is critical.
affects: *
gotchaThe format option 'level' with negative values counts from the project root, which may include unwanted directories if project root detection fails.
fix
Test with your project structure and adjust level or extensions accordingly.
affects: *
gotchaThe plugin does not support TypeScript natively; TypeScript files must be handled by Babel with appropriate presets.
fix
Use @babel/preset-typescript and ensure the plugin runs after it.
affects: *
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'js-logger'
js-logger is not installed or not in node_modules.
fix
Install js-logger as a dependency: npm install js-logger --save
Error: Cannot find module 'babel-plugin-js-logger'
The plugin is not installed or not listed in .babelrc plugins correctly.
fix
Install the plugin: npm install babel-plugin-js-logger --save-dev, then add 'js-logger' to .babelrc plugins array.
TypeError: require(...).useDefaults is not a function
js-logger is not initialized properly.
fix
Call require('js-logger').useDefaults() before using the generated logger variables.
Upgrade
Version history
1.0.17latest on npm
Audit
Dependencies
js-loggerrequiredThe plugin generates code that requires js-logger at runtime
Agent activity
2 hits · last 30 days
node
2
Resources
babel-plugin-js-logger — npm install babel-plugin-js-logger · libregistry