{"id":19238,"library":"babel-plugin-undebug","title":"babel-plugin-undebug","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/wooorm/babel-plugin-undebug","tags":["javascript","babel","plugin","debug","undebug","typescript"],"install":[{"cmd":"npm install babel-plugin-undebug","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-undebug","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-undebug","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency to run as a Babel plugin","package":"@babel/core","optional":false}],"imports":[{"note":"Default export only; named export does not exist. ESM-only since v2.","wrong":"import { babelPluginUndebug } from 'babel-plugin-undebug'","symbol":"babelPluginUndebug","correct":"import babelPluginUndebug from 'babel-plugin-undebug'"},{"note":"CJS require is not supported in v3 (ESM-only). Use dynamic import or configure via babel config file.","wrong":"const babelPluginUndebug = require('babel-plugin-undebug')","symbol":"babelPluginUndebug","correct":"module.exports = { plugins: [['babel-plugin-undebug', options]] }"},{"note":"Babel plugin name must be the full npm package name when using string shorthand. Version mismatch can cause undefined plugin errors.","wrong":"plugins: ['undebug']","symbol":"babel-plugin-undebug","correct":"plugins: ['babel-plugin-undebug']"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-undebug @babel/core @babel/cli\n\n// babel.config.json\n{\n  \"plugins\": [\"babel-plugin-undebug\"]\n}\n\n// example.js\nconst debug = require('debug')('myapp');\nlet count = 0;\ndebug('Count is %d', count++);\ncount++;\ndebug('Now count is %d', count);\nconsole.log('Final', count);\n\n// Run: npx babel example.js --out-file output.js\n// output.js:\n// let count = 0;\n// count++;\n// console.log('Final', count);\n\ndebug('Unreachable after removal');","lang":"javascript","description":"Demonstrates installing, configuring, and running babel-plugin-undebug to strip debug calls from a Node.js script, preserving other statements."},"warnings":[{"fix":"Upgrade to Node.js 18+ or use babel-plugin-undebug@^2.0.0","message":"Dropped support for Node 16 in v3.0.0","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use ESM import or dynamic import(). If using CommonJS, pin to version 1.x.","message":"Conversion to ESM-only in v2.0.0: require() is no longer supported","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update TypeScript to >=4.5 or configure skipLibCheck","message":"TypeScript types now use @import JSDoc syntax (v3). May affect older TypeScript versions or tooling","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Refactor side effects out of debug arguments before running the plugin.","message":"Removes entire debug() call including side-effect expressions like debug(obj.x++) – be aware of side effects being dropped","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev babel-plugin-undebug` and ensure plugins array uses full name: 'babel-plugin-undebug'","cause":"Package not installed or named incorrectly in Babel config","error":"Error: Cannot find module 'babel-plugin-undebug'"},{"fix":"Use ESM import, or switch to dynamic import(). If you need CJS, downgrade to v1.x.","cause":"Using require() to load the plugin in a CommonJS context with v2/v3","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/babel-plugin-undebug/index.js from ... not supported."},{"fix":"Change import from `import { babelPluginUndebug }` to `import babelPluginUndebug`","cause":"Attempting to use a named export instead of default export","error":"TypeError: babelPluginUndebug is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}