Registry / devops / babel-plugin-dev

babel-plugin-dev

JSON →
library1.0.0jsnpmunverified

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.

npm install babel-plugin-dev
INSTALL
IMPORT
SIG · BABEL-PLUGIN-DEV
B
babel-plugin-dev
devopsjavascriptv1.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.

default plugin
module.exports = { plugins: ['dev'] }
const plugin = require('babel-plugin-dev'); module.exports = { plugins: [plugin] }
In .babelrc or babel.config.js, reference the plugin by its string name 'dev', not by requiring the package.
Programmatic usage with Babel core
const babel = require('@babel/core'); babel.transform(code, { plugins: ['dev'] })
const babel = require('babel-core'); babel.transform(code, { plugins: ['dev'] })
For Babel 7, use @babel/core. For Babel 6, use babel-core. The plugin works with both.
CLI usage
babel --plugins dev script.js
babel --plugin babel-plugin-dev script.js
Use the short name 'dev', not the full package name. Babel resolves the name automatically.

Configures Babel to replace __DEV__ with process.env.NODE_ENV !== 'production' for conditional debug code.

// File: test.js const __DEV__ = true; // In production, __DEV__ is replaced with process.env.NODE_ENV !== 'production' if (__DEV__) { console.log('debug info'); } // .babelrc { "plugins": ["dev"] } // Run: // npx babel test.js --plugins dev // Output: if (process.env.NODE_ENV !== 'production') { console.log('debug info'); }
Debug
Known issues
gotchaThe plugin replaces the global identifier `__DEV__` in all contexts, not just in variable declarations or expressions.
fix
Ensure `__DEV__` is not used as a variable name for other purposes; if you need scoped dev flags, use a different approach.
affects: >=1.0.0
gotchaThe replacement is textual and does not check for reassignment. If you assign `__DEV__ = false`, the replacement still occurs.
fix
Do not reassign `__DEV__`. Use it only as a read-only global flag.
affects: >=1.0.0
deprecatedThis plugin is in maintenance mode. It works with Babel 6 and 7 but no new features are planned.
fix
Consider using @babel/plugin-transform-inline-environment-variables for more flexibility, or manually check process.env.NODE_ENV.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-dev'
The package is not installed or is installed globally instead of locally.
fix
Run `npm install babel-plugin-dev --save-dev` in your project root.
Error: __DEV__ is not defined
The plugin is not applied or Babel compilation is not happening.
fix
Add 'dev' to your Babel plugins list (e.g., in .babelrc) and ensure you are compiling the file with Babel.
SyntaxError: Unexpected token (1:10) > 1 | if (__DEV__) {
The file is not being parsed by Babel (e.g., using node directly without transpilation).
fix
Make sure to run the file through Babel before execution, e.g., using @babel/node or a build step.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-dev — npm install babel-plugin-dev · libregistry