{"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,"search_vec":"'1.0.0':24 'altern':40 'argcount':47 'argument':13 'babel':2,6,58 'babel-plugin-strip-invari':1 'build':19 'call':16 'common':30 'current':20 'custom':50 'depend':56 'essenti':12 'first':25 'footgun':31 'implement':52 'invari':5,15,38,51,60 'javascript':57 'lightweight':53 'manual':42 'messag':39,63 'minifi':33 'non':11 'non-essenti':10 'offer':44 'optim':43 'option':48 'plugin':3,7,59 'pragma':45 'product':18,61 'releas':26 'remov':9,36,62 'runtim':55 'solv':28 'stabl':21 'strip':4 'verbos':37 'version':22","created_at":"2026-04-25T11:16:24.629511+00:00","updated_at":"2026-04-25T11:16:24.629511+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/husscode/babel-plugin-strip-invariant","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/babel-plugin-strip-invariant","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}