{"id":19042,"library":"babel-plugin-dev","title":"babel-plugin-dev","description":"Simple Babel plugin that replaces the global `__DEV__` identifier with `process.env.NODE_ENV !== 'production'`, allowing developers to conditionally include debug-only code without runtime overhead. Version 1.0.0 is stable and final; no new releases expected. It is lightweight with zero dependencies, works with Babel 6 and 7, and is used in production by many React-based libraries. Unlike alternatives like babel-plugin-transform-inline-environment-variables or manual if-blocks, this plugin provides a single-purpose, semantic `__DEV__` syntax with no configuration required.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/Zenwolf/babel-plugin-dev","tags":["javascript","babel-plugin","dev","debug"],"install":[{"cmd":"npm install babel-plugin-dev","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-dev","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-dev","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"In .babelrc or babel.config.js, reference the plugin by its string name 'dev', not by requiring the package.","wrong":"const plugin = require('babel-plugin-dev'); module.exports = { plugins: [plugin] }","symbol":"default plugin","correct":"module.exports = { plugins: ['dev'] }"},{"note":"For Babel 7, use @babel/core. For Babel 6, use babel-core. The plugin works with both.","wrong":"const babel = require('babel-core'); babel.transform(code, { plugins: ['dev'] })","symbol":"Programmatic usage with Babel core","correct":"const babel = require('@babel/core'); babel.transform(code, { plugins: ['dev'] })"},{"note":"Use the short name 'dev', not the full package name. Babel resolves the name automatically.","wrong":"babel --plugin babel-plugin-dev script.js","symbol":"CLI usage","correct":"babel --plugins dev script.js"}],"quickstart":{"code":"// File: test.js\nconst __DEV__ = true;\n// In production, __DEV__ is replaced with process.env.NODE_ENV !== 'production'\nif (__DEV__) {\n  console.log('debug info');\n}\n\n// .babelrc\n{\n  \"plugins\": [\"dev\"]\n}\n\n// Run:\n// npx babel test.js --plugins dev\n// Output: if (process.env.NODE_ENV !== 'production') { console.log('debug info'); }","lang":"javascript","description":"Configures Babel to replace __DEV__ with process.env.NODE_ENV !== 'production' for conditional debug code."},"warnings":[{"fix":"Ensure `__DEV__` is not used as a variable name for other purposes; if you need scoped dev flags, use a different approach.","message":"The plugin replaces the global identifier `__DEV__` in all contexts, not just in variable declarations or expressions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not reassign `__DEV__`. Use it only as a read-only global flag.","message":"The replacement is textual and does not check for reassignment. If you assign `__DEV__ = false`, the replacement still occurs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using @babel/plugin-transform-inline-environment-variables for more flexibility, or manually check process.env.NODE_ENV.","message":"This plugin is in maintenance mode. It works with Babel 6 and 7 but no new features are planned.","severity":"deprecated","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 babel-plugin-dev --save-dev` in your project root.","cause":"The package is not installed or is installed globally instead of locally.","error":"Error: Cannot find module 'babel-plugin-dev'"},{"fix":"Add 'dev' to your Babel plugins list (e.g., in .babelrc) and ensure you are compiling the file with Babel.","cause":"The plugin is not applied or Babel compilation is not happening.","error":"Error: __DEV__ is not defined"},{"fix":"Make sure to run the file through Babel before execution, e.g., using @babel/node or a build step.","cause":"The file is not being parsed by Babel (e.g., using node directly without transpilation).","error":"SyntaxError: Unexpected token (1:10)\n> 1 | if (__DEV__) {"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}