{"id":19171,"library":"babel-plugin-strip-invariant","title":"babel-plugin-strip-invariant","description":"Babel plugin to remove non-essential arguments from invariant() calls in production builds. Current stable version is 1.0.0, first release. It solves a common footgun where minifiers don't remove verbose invariant messages. Alternative to manual optimization; offers pragma and argCount options for custom invariant implementations. Lightweight, no runtime dependencies.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/husscode/babel-plugin-strip-invariant","tags":["javascript","babel","plugin","invariant","production","remove","messages"],"install":[{"cmd":"npm install babel-plugin-strip-invariant","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-strip-invariant","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-strip-invariant","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a Babel plugin, not a JS module. It's loaded via .babelrc or babel.config.js, not imported directly.","wrong":"import stripInvariant from 'babel-plugin-strip-invariant'","symbol":"default","correct":"module.exports = { plugins: ['babel-plugin-strip-invariant'] }"},{"note":"Use string name 'babel-plugin-strip-invariant' in plugins array, not require().","wrong":"plugins: [[require('babel-plugin-strip-invariant'), { pragma: 'myFunc' }]]","symbol":"pragma","correct":"['babel-plugin-strip-invariant', { pragma: 'myFunc' }]"},{"note":"Option key is 'argCount', not 'args'.","wrong":"['babel-plugin-strip-invariant', { args: 2 }]","symbol":"argCount","correct":"['babel-plugin-strip-invariant', { argCount: 2 }]"}],"quickstart":{"code":"// .babelrc\n{\n  \"env\": {\n    \"production\": {\n      \"plugins\": [\"babel-plugin-strip-invariant\"]\n    }\n  }\n}\n\n// or babel.config.js\nmodule.exports = {\n  env: {\n    production: {\n      plugins: ['babel-plugin-strip-invariant']\n    }\n  }\n};\n\n// input\ninvariant(condition, 'This is a verbose message that will be removed in production');\n\n// output (production build)\ninvariant(condition);","lang":"javascript","description":"Configure Babel to strip the message argument from invariant() calls in production builds."},"warnings":[{"fix":"Ensure the plugin is placed under the 'production' env block in .babelrc or use BABEL_ENV=production.","message":"Plugin only runs in production environment as defined in .babelrc; development builds are unaffected.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually import or define the custom function in your code.","message":"If using a custom pragma, the function must be imported/defined; plugin does not inject anything.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Reorder invocation so that arguments to keep are at the beginning.","message":"argCount removes trailing arguments; ensure essential arguments are first.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate if plugin still works with your Babel version; may need fork.","message":"Plugin has zero open issues and no updates since 2018; consider active alternatives like babel-plugin-transform-define.","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":"Install and import the 'invariant' package: npm install invariant and add import invariant from 'invariant';","cause":"The invariant function is not imported or available in scope after stripping arguments.","error":"SyntaxError: unknown: identifier 'invariant' is not defined"},{"fix":"Use string plugin name: 'babel-plugin-strip-invariant'","cause":"Using require() or a non-serializable object in plugins array.","error":"Error: .babelrc env.production.plugins[0] must be a string or array"},{"fix":"Use Babel 6 or check if fork exists for Babel 7.","cause":"Plugin not updated for Babel 7 API.","error":"Babel 7 compatibility: Plugin/Preset files are not allowed to export objects, only functions"},{"fix":"Run npm install --save-dev babel-plugin-strip-invariant","cause":"Package not installed.","error":"Module not found: Can't resolve 'babel-plugin-strip-invariant'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}