unassert-rollup-plugin

raw JSON →
2.0.0 verified Mon Apr 27 auth: no javascript

A Rollup plugin to remove assertion calls from production bundles using Unassert. Current stable version is 2.0.0, released with Unassert 2.0.0. Release cadence is low; v1 used Unassert 1.6.0. It strips assert, power-assert, and custom assertion statements, reducing bundle size and avoiding runtime assertions in production. Key differentiator: integrates Unassert's removal logic directly into the Rollup build pipeline, supporting include/exclude patterns, sourcemaps, and custom assertion patterns.

error TypeError: unassert is not a function
cause Using default import when the plugin exports a named function.
fix
Change to: import { unassert } from 'unassert-rollup-plugin';
error Error: Could not resolve 'unassert-rollup-plugin'
cause Missing installation or incorrect import path.
fix
Run: npm install -D unassert-rollup-plugin
breaking v2.0.0 upgraded to Unassert 2.0.0, which may have different behavior regarding assertion pattern matching.
fix Review Unassert 2.0.0 changelog for changes to assertion patterns and require/import handling.
gotcha The plugin only processes JavaScript files by default. For TypeScript or other file types, you must specify the 'include' option.
fix Set 'include' to '**/*.ts' or similar if using TypeScript.
deprecated Default export is deprecated in v2? The README shows both named and default exports, but the TypeScript types may only export named. Default import may stop working in future releases.
fix Always use named import: import { unassert } from 'unassert-rollup-plugin';
gotcha Setting sourcemap: false removes assert calls from the output but also suppresses sourcemaps for the transformed code, making debugging harder.
fix Keep sourcemap: true (default) to maintain debug ability.
npm install unassert-rollup-plugin
yarn add unassert-rollup-plugin
pnpm add unassert-rollup-plugin

Rollup configuration using unassert plugin to remove assertion calls, with inclusion/exclusion patterns and sourcemap support.

import { unassert } from 'unassert-rollup-plugin';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'esm'
  },
  plugins: [
    unassert({
      include: ['**/*.js'],
      exclude: ['test/**'],
      sourcemap: true,
      assertionPatterns: ['assert(value)', 'assert.ok(value)', 'assert.equal(actual, expected)']
    })
  ]
};