Registry / testing / babel-plugin-unassert

babel-plugin-unassert

JSON →
library3.2.0jsnpmunverified

Babel plugin that removes assertion calls (assert, console.assert, power-assert) from production builds. Current stable version is 3.2.0, compatible with Babel 7. Release cadence is low, with major versions tied to Babel major versions. Key differentiator: allows full use of assertions during development without runtime overhead in production, with support for ES modules and power-assert integration. Alternative to manual conditional wrapping or dead-code elimination.

npm install babel-plugin-unassert
INSTALL
IMPORT
SIG · BABEL-PLUGIN-UNASS
B
babel-plugin-unassert
testingjavascriptv3.2.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 export
import unassert from 'babel-plugin-unassert'; module.exports = { plugins: ['babel-plugin-unassert'] };
import { default } from 'babel-plugin-unassert'; const plugin = require('babel-plugin-unassert').default;
Plugin is a CommonJS module; use string name in Babel config or require() directly. No named exports.
require()
const unassert = require('babel-plugin-unassert');
const { unassert } = require('babel-plugin-unassert'); const unassert = require('babel-plugin-unassert').unassert;
Only default export exists; destructuring or .unassert will be undefined.
ESM import (if bundler allows)
import unassert from 'babel-plugin-unassert';
import { unassert } from 'babel-plugin-unassert'; import * as unassert from 'babel-plugin-unassert';
Package does not have a 'module' field; default import works if bundler resolves to CJS. Named import does not exist.

Demonstrates using babel-plugin-unassert via Babel config to remove assertions in production. Shows conditional plugin addition based on NODE_ENV.

// babel.config.js module.exports = function (api) { const presets = ['@babel/env']; const plugins = []; if (process.env.NODE_ENV === 'production') { plugins.push('babel-plugin-unassert'); } return { presets, plugins }; }; // src/math.js const assert = require('assert'); function add(a, b) { console.assert(typeof a === 'number'); assert(!isNaN(a)); return a + b; } // After build: // function add(a, b) { // return a + b; // }
Debug
Known issues
breakingBabel 7 is incompatible with Babel 6; babel-plugin-unassert v3 requires Babel 7.
fix
Use babel-plugin-unassert@2 for Babel 6, @1 for Babel <=5.
affects: >=3.0.0
breakingBabel 6 is incompatible with Babel 5; babel-plugin-unassert v2 requires Babel 6.
fix
Use babel-plugin-unassert@1 for Babel 5 or lower.
affects: >=2.0.0 <3.0.0
deprecatedbabel-plugin-unassert v1 is deprecated; use v2 or v3 with appropriate Babel version.
fix
Upgrade to v2 (Babel 6) or v3 (Babel 7) as per your Babel version.
affects: 1.x
gotchaPlugin removes only calls to assert, console.assert, and power-assert modules. Custom assert functions are not removed.
fix
Ensure your assertions use standard assert module or power-assert. Alternatively, ensure custom functions have no side effects.
affects: all
gotchaUsing require('babel-plugin-unassert') in Node returns the plugin function, not an object with a default property. Importing with ES named import fails.
fix
Use require('babel-plugin-unassert') or import default. Never destructure as { unassert }.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-unassert'
Package not installed or incorrectly required.
fix
Run 'npm install --save-dev babel-plugin-unassert' and ensure it's in node_modules.
Error: [BABEL] unknown: Plugin babel-plugin-unassert is not a valid plugin (Error: Cannot find module 'babel-plugin-unassert')
String name in Babel config but plugin not installed.
fix
Install the plugin and ensure node_modules path is correct. Check for typos.
TypeError: babelPluginUnassert is not a function
Trying to use the default export incorrectly, e.g., destructuring.
fix
Use const plugin = require('babel-plugin-unassert'); not const { unassert } = require('babel-plugin-unassert');
Assertions not removed in production build
Plugin not added to Babel plugins list, or NODE_ENV not set correctly.
fix
Add 'babel-plugin-unassert' to plugins array when NODE_ENV === 'production'. Verify Babel config applies during build.
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies
@babel/coreoptionalpeer dependency for Babel plugin
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
babel-plugin-unassert — npm install babel-plugin-unassert · libregistry