{"id":19236,"library":"babel-plugin-unassert","title":"babel-plugin-unassert","description":"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.","status":"active","version":"3.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/unassert-js/babel-plugin-unassert","tags":["javascript","DbC","assert","babel","babel-plugin","unassert"],"install":[{"cmd":"npm install babel-plugin-unassert","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-unassert","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-unassert","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for Babel plugin","package":"@babel/core","optional":true}],"imports":[{"note":"Plugin is a CommonJS module; use string name in Babel config or require() directly. No named exports.","wrong":"import { default } from 'babel-plugin-unassert'; const plugin = require('babel-plugin-unassert').default;","symbol":"default export","correct":"import unassert from 'babel-plugin-unassert'; module.exports = { plugins: ['babel-plugin-unassert'] };"},{"note":"Only default export exists; destructuring or .unassert will be undefined.","wrong":"const { unassert } = require('babel-plugin-unassert'); const unassert = require('babel-plugin-unassert').unassert;","symbol":"require()","correct":"const unassert = require('babel-plugin-unassert');"},{"note":"Package does not have a 'module' field; default import works if bundler resolves to CJS. Named import does not exist.","wrong":"import { unassert } from 'babel-plugin-unassert'; import * as unassert from 'babel-plugin-unassert';","symbol":"ESM import (if bundler allows)","correct":"import unassert from 'babel-plugin-unassert';"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = function (api) {\n  const presets = ['@babel/env'];\n  const plugins = [];\n\n  if (process.env.NODE_ENV === 'production') {\n    plugins.push('babel-plugin-unassert');\n  }\n\n  return {\n    presets,\n    plugins\n  };\n};\n\n// src/math.js\nconst assert = require('assert');\n\nfunction add(a, b) {\n  console.assert(typeof a === 'number');\n  assert(!isNaN(a));\n  return a + b;\n}\n\n// After build:\n// function add(a, b) {\n//   return a + b;\n// }","lang":"javascript","description":"Demonstrates using babel-plugin-unassert via Babel config to remove assertions in production. Shows conditional plugin addition based on NODE_ENV."},"warnings":[{"fix":"Use babel-plugin-unassert@2 for Babel 6, @1 for Babel <=5.","message":"Babel 7 is incompatible with Babel 6; babel-plugin-unassert v3 requires Babel 7.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use babel-plugin-unassert@1 for Babel 5 or lower.","message":"Babel 6 is incompatible with Babel 5; babel-plugin-unassert v2 requires Babel 6.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Upgrade to v2 (Babel 6) or v3 (Babel 7) as per your Babel version.","message":"babel-plugin-unassert v1 is deprecated; use v2 or v3 with appropriate Babel version.","severity":"deprecated","affected_versions":"1.x"},{"fix":"Ensure your assertions use standard assert module or power-assert. Alternatively, ensure custom functions have no side effects.","message":"Plugin removes only calls to assert, console.assert, and power-assert modules. Custom assert functions are not removed.","severity":"gotcha","affected_versions":"all"},{"fix":"Use require('babel-plugin-unassert') or import default. Never destructure as { unassert }.","message":"Using require('babel-plugin-unassert') in Node returns the plugin function, not an object with a default property. Importing with ES named import fails.","severity":"gotcha","affected_versions":"all"}],"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-unassert' and ensure it's in node_modules.","cause":"Package not installed or incorrectly required.","error":"Error: Cannot find module 'babel-plugin-unassert'"},{"fix":"Install the plugin and ensure node_modules path is correct. Check for typos.","cause":"String name in Babel config but plugin not installed.","error":"Error: [BABEL] unknown: Plugin babel-plugin-unassert is not a valid plugin (Error: Cannot find module 'babel-plugin-unassert')"},{"fix":"Use const plugin = require('babel-plugin-unassert'); not const { unassert } = require('babel-plugin-unassert');","cause":"Trying to use the default export incorrectly, e.g., destructuring.","error":"TypeError: babelPluginUnassert is not a function"},{"fix":"Add 'babel-plugin-unassert' to plugins array when NODE_ENV === 'production'. Verify Babel config applies during build.","cause":"Plugin not added to Babel plugins list, or NODE_ENV not set correctly.","error":"Assertions not removed in production build"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}