{"id":19041,"library":"babel-plugin-dev-expression","title":"babel-plugin-dev-expression","description":"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.","status":"active","version":"0.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/4Catalyzer/babel-plugin-dev-expression","tags":["javascript","facebook","react","babel","dev-expression"],"install":[{"cmd":"npm install babel-plugin-dev-expression","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-dev-expression","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-dev-expression","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: required to run as a Babel plugin","package":"@babel/core","optional":false}],"imports":[{"note":"CJS-only; the plugin is CommonJS and not ESM. Use require() in Node/Babel config.","wrong":"import plugin from 'babel-plugin-dev-expression'","symbol":"default export","correct":"module.exports = require('babel-plugin-dev-expression')"},{"note":"The export is a single function, not a named export. Use default require.","wrong":"import { devExpression } from 'babel-plugin-dev-expression'","symbol":"devExpression","correct":"const devExpression = require('babel-plugin-dev-expression')"},{"note":"This plugin takes no options. Do not pass an options object; it will be ignored.","wrong":"plugins: [['babel-plugin-dev-expression', { /* options */ }]]","symbol":"Babel config usage","correct":"plugins: ['dev-expression']"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  plugins: [\n    'babel-plugin-dev-expression'\n  ]\n};\n\n// Before (source.js):\nconst __DEV__ = true;\ninvariant(condition, 'msg %s', arg);\nwarning(condition, 'msg %s', arg);\n\n// After (production build):\nprocess.env.NODE_ENV !== 'production';\nif (!condition) {\n  if (\"production\" !== process.env.NODE_ENV) {\n    invariant(false, 'msg %s', arg);\n  } else {\n    invariant(false);\n  }\n}\nif (\"production\" !== process.env.NODE_ENV) {\n  warning(condition, 'msg %s', arg);\n}","lang":"javascript","description":"Shows Babel config and how __DEV__, invariant, and warning are transformed in production."},"warnings":[{"fix":"In Jest: setupFiles or jest.globals; in Mocha: global.__DEV__ = true;","message":"The transform does NOT run when NODE_ENV is 'test'. You must define __DEV__ as a global in your test environment.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to Babel 6/7 or stay on babel-plugin-dev-expression@0.1.x.","message":"v0.2.0 dropped Babel 5 support and required Babel 6+. If you are on Babel 5, pin to v0.1.0.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Evaluate alternatives; the plugin is stable but unmaintained.","message":"This package is a mirror of Facebook's plugin and may not receive updates. Consider using @babel/plugin-transform-prod-expressions or manual optimization.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure NODE_ENV is properly set to 'production' for builds, or disable the plugin in development.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.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-dev-expression or add to package.json.","cause":"Not installed or misconfigured in pnpm / yarn PnP.","error":"Cannot find module 'babel-plugin-dev-expression'"},{"fix":"Use require('babel-plugin-dev-expression') or string shorthand 'dev-expression'.","cause":"Using import or ES module syntax for the plugin in a CommonJS config file.","error":"Error: .plugins[0][0] must be a string, object, function"},{"fix":"Ensure babel-plugin-dev-expression is in the plugins list and NODE_ENV is set to 'production'.","cause":"invariant was stripped incorrectly because the plugin didn't run (NODE_ENV=test or misconfiguration).","error":"Invariant failed: Minified React error #31"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}