Registry / devops / babel-plugin-dev-expression

babel-plugin-dev-expression

JSON →
library0.2.3jsnpmunverified

A Babel plugin that mirrors Facebook's dev-expression transform, reducing or eliminating development checks (invariant, warning, __DEV__) from production code. Stable version 0.2.3, low release cadence. It replaces __DEV__ with process.env.NODE_ENV !== 'production', optimizes invariant and warning calls by wrapping them with environment checks. Differentiates from manual conditional code by automating transforms and handling edge cases like stringification.

npm install babel-plugin-dev-expression
INSTALL
IMPORT
SIG · BABEL-PLUGIN-DEV-E
B
babel-plugin-dev-expression
devopsjavascriptv0.2.3
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 export
module.exports = require('babel-plugin-dev-expression')
import plugin from 'babel-plugin-dev-expression'
CJS-only; the plugin is CommonJS and not ESM. Use require() in Node/Babel config.
devExpression
const devExpression = require('babel-plugin-dev-expression')
import { devExpression } from 'babel-plugin-dev-expression'
The export is a single function, not a named export. Use default require.
Babel config usage
plugins: ['dev-expression']
plugins: [['babel-plugin-dev-expression', { /* options */ }]]
This plugin takes no options. Do not pass an options object; it will be ignored.

Shows Babel config and how __DEV__, invariant, and warning are transformed in production.

// babel.config.js module.exports = { plugins: [ 'babel-plugin-dev-expression' ] }; // Before (source.js): const __DEV__ = true; invariant(condition, 'msg %s', arg); warning(condition, 'msg %s', arg); // After (production build): process.env.NODE_ENV !== 'production'; if (!condition) { if ("production" !== process.env.NODE_ENV) { invariant(false, 'msg %s', arg); } else { invariant(false); } } if ("production" !== process.env.NODE_ENV) { warning(condition, 'msg %s', arg); }
Debug
Known issues
gotchaThe transform does NOT run when NODE_ENV is 'test'. You must define __DEV__ as a global in your test environment.
fix
In Jest: setupFiles or jest.globals; in Mocha: global.__DEV__ = true;
affects: >=0.1.0
breakingv0.2.0 dropped Babel 5 support and required Babel 6+. If you are on Babel 5, pin to v0.1.0.
fix
Upgrade to Babel 6/7 or stay on babel-plugin-dev-expression@0.1.x.
affects: >=0.2.0
deprecatedThis package is a mirror of Facebook's plugin and may not receive updates. Consider using @babel/plugin-transform-prod-expressions or manual optimization.
fix
Evaluate alternatives; the plugin is stable but unmaintained.
affects: >=0.0.0
gotchaThe plugin replaces __DEV__ even in non-production builds if NODE_ENV is set. If you rely on __DEV__ being a global truthy constant, the transform will break it.
fix
Ensure NODE_ENV is properly set to 'production' for builds, or disable the plugin in development.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'babel-plugin-dev-expression'
Not installed or misconfigured in pnpm / yarn PnP.
fix
Run npm install --save-dev babel-plugin-dev-expression or add to package.json.
Error: .plugins[0][0] must be a string, object, function
Using import or ES module syntax for the plugin in a CommonJS config file.
fix
Use require('babel-plugin-dev-expression') or string shorthand 'dev-expression'.
Invariant failed: Minified React error #31
invariant was stripped incorrectly because the plugin didn't run (NODE_ENV=test or misconfiguration).
fix
Ensure babel-plugin-dev-expression is in the plugins list and NODE_ENV is set to 'production'.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies
@babel/corerequiredpeer dependency: required to run as a Babel plugin
Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-dev-expression — npm install babel-plugin-dev-expression · libregistry