Registry / devops / babel-plugin-undebug

babel-plugin-undebug

JSON →
library3.0.0jsnpmunverified

A Babel plugin that strips `debug` function calls from production code to reduce bundle size and eliminate debug overhead. Version 3.0.0 is ESM-only, requires Node.js 18+, and ships TypeScript types. It handles both CommonJS (`require('debug')`) and ESM (`import debug from 'debug'`) imports, removing all debug calls including side-effectful expressions like `d(value++)`. Unlike manual removal, it automates stripping without source code changes.

npm install babel-plugin-undebug
INSTALL
IMPORT
SIG · BABEL-PLUGIN-UNDEB
B
babel-plugin-undebug
devopsjavascriptv3.0.0
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.

babelPluginUndebug
import babelPluginUndebug from 'babel-plugin-undebug'
import { babelPluginUndebug } from 'babel-plugin-undebug'
Default export only; named export does not exist. ESM-only since v2.
babelPluginUndebug
module.exports = { plugins: [['babel-plugin-undebug', options]] }
const babelPluginUndebug = require('babel-plugin-undebug')
CJS require is not supported in v3 (ESM-only). Use dynamic import or configure via babel config file.
babel-plugin-undebug
plugins: ['babel-plugin-undebug']
plugins: ['undebug']
Babel plugin name must be the full npm package name when using string shorthand. Version mismatch can cause undefined plugin errors.

Demonstrates installing, configuring, and running babel-plugin-undebug to strip debug calls from a Node.js script, preserving other statements.

// Install: npm install --save-dev babel-plugin-undebug @babel/core @babel/cli // babel.config.json { "plugins": ["babel-plugin-undebug"] } // example.js const debug = require('debug')('myapp'); let count = 0; debug('Count is %d', count++); count++; debug('Now count is %d', count); console.log('Final', count); // Run: npx babel example.js --out-file output.js // output.js: // let count = 0; // count++; // console.log('Final', count); debug('Unreachable after removal');
Debug
Known issues
breakingDropped support for Node 16 in v3.0.0
fix
Upgrade to Node.js 18+ or use babel-plugin-undebug@^2.0.0
affects: >=3.0.0
breakingConversion to ESM-only in v2.0.0: require() is no longer supported
fix
Use ESM import or dynamic import(). If using CommonJS, pin to version 1.x.
affects: >=2.0.0
deprecatedTypeScript types now use @import JSDoc syntax (v3). May affect older TypeScript versions or tooling
fix
Update TypeScript to >=4.5 or configure skipLibCheck
affects: >=3.0.0
gotchaRemoves entire debug() call including side-effect expressions like debug(obj.x++) – be aware of side effects being dropped
fix
Refactor side effects out of debug arguments before running the plugin.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-undebug'
Package not installed or named incorrectly in Babel config
fix
Run `npm install --save-dev babel-plugin-undebug` and ensure plugins array uses full name: 'babel-plugin-undebug'
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/babel-plugin-undebug/index.js from ... not supported.
Using require() to load the plugin in a CommonJS context with v2/v3
fix
Use ESM import, or switch to dynamic import(). If you need CJS, downgrade to v1.x.
TypeError: babelPluginUndebug is not a function
Attempting to use a named export instead of default export
fix
Change import from `import { babelPluginUndebug }` to `import babelPluginUndebug`
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
@babel/corerequiredRequired as a peer dependency to run as a Babel plugin
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
babel-plugin-undebug — npm install babel-plugin-undebug · libregistry