Registry / devops / babel-plugin-strip-invariant

babel-plugin-strip-invariant

JSON →
library1.0.0jsnpmunverified

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.

npm install babel-plugin-strip-invariant
INSTALL
IMPORT
SIG · BABEL-PLUGIN-STRIP
B
babel-plugin-strip-invariant
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
module.exports = { plugins: ['babel-plugin-strip-invariant'] }
import stripInvariant from 'babel-plugin-strip-invariant'
This is a Babel plugin, not a JS module. It's loaded via .babelrc or babel.config.js, not imported directly.
pragma
['babel-plugin-strip-invariant', { pragma: 'myFunc' }]
plugins: [[require('babel-plugin-strip-invariant'), { pragma: 'myFunc' }]]
Use string name 'babel-plugin-strip-invariant' in plugins array, not require().
argCount
['babel-plugin-strip-invariant', { argCount: 2 }]
['babel-plugin-strip-invariant', { args: 2 }]
Option key is 'argCount', not 'args'.

Configure Babel to strip the message argument from invariant() calls in production builds.

// .babelrc { "env": { "production": { "plugins": ["babel-plugin-strip-invariant"] } } } // or babel.config.js module.exports = { env: { production: { plugins: ['babel-plugin-strip-invariant'] } } }; // input invariant(condition, 'This is a verbose message that will be removed in production'); // output (production build) invariant(condition);
Debug
Known issues
gotchaPlugin only runs in production environment as defined in .babelrc; development builds are unaffected.
fix
Ensure the plugin is placed under the 'production' env block in .babelrc or use BABEL_ENV=production.
affects: >=1.0.0
gotchaIf using a custom pragma, the function must be imported/defined; plugin does not inject anything.
fix
Manually import or define the custom function in your code.
affects: >=1.0.0
gotchaargCount removes trailing arguments; ensure essential arguments are first.
fix
Reorder invocation so that arguments to keep are at the beginning.
affects: >=1.0.0
deprecatedPlugin has zero open issues and no updates since 2018; consider active alternatives like babel-plugin-transform-define.
fix
Evaluate if plugin still works with your Babel version; may need fork.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: unknown: identifier 'invariant' is not defined
The invariant function is not imported or available in scope after stripping arguments.
fix
Install and import the 'invariant' package: npm install invariant and add import invariant from 'invariant';
Error: .babelrc env.production.plugins[0] must be a string or array
Using require() or a non-serializable object in plugins array.
fix
Use string plugin name: 'babel-plugin-strip-invariant'
Babel 7 compatibility: Plugin/Preset files are not allowed to export objects, only functions
Plugin not updated for Babel 7 API.
fix
Use Babel 6 or check if fork exists for Babel 7.
Module not found: Can't resolve 'babel-plugin-strip-invariant'
Package not installed.
fix
Run npm install --save-dev babel-plugin-strip-invariant
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