rollup-plugin-deassert

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

Rollup plugin to remove assert, invariant, and similar statements from production bundles. Current stable version: 1.3.2 (2024-08-23). Release cadence: active development with frequent updates. Key differentiator: supports both ESM and CJS, ships TypeScript definitions, and handles conditional expressions. Unlike alternatives, it integrates naturally with Rollup's plugin system and respects source maps. Peer dependencies: acorn ^8.12.1 and rollup ^4.20.0.

error Error: Cannot find module 'rollup-plugin-deassert'
cause Package not installed or named incorrectly.
fix
Run 'npm install -D rollup-plugin-deassert' or check package.json for correct name.
error TypeError: deassert is not a function
cause Using default import incorrectly or wrong import path.
fix
Use 'import { rollupPlugin as deassert } from 'rollup-plugin-deassert'' instead of 'import deassert from ...'.
error Error: The plugin deassert does not exist or is not a function.
cause Incorrect import or plugin not added to rollup config.
fix
Ensure the import is correct and the plugin is included in the plugins array: plugins: [deassert()].
error AssertionError [ERR_ASSERTION]: false == true
cause The plugin didn't remove the assert statement (e.g., when include option is missing for TypeScript).
fix
Add 'include: ["**/*.ts"]' to deassert options if using TypeScript files.
gotcha Default export may be removed in future versions; use named export 'rollupPlugin' for stability.
fix Replace default import { deassert } from 'rollup-plugin-deassert' with named import { rollupPlugin as deassert } from 'rollup-plugin-deassert'.
breaking Version 1.3.0 introduced support for conditional expressions; previous versions would ignore assert inside ternary/if conditions.
fix Upgrade to >=1.3.0 to handle conditional expressions.
gotcha If using TypeScript, you must explicitly set include: ['**/*.ts'] in options; otherwise the plugin only processes JavaScript files.
fix Add include: ['**/*.ts'] or appropriate glob to deassert() options.
deprecated The package 'rollup-plugin-deassert' is deprecated in favor of the unified 'deassert' package that supports multiple bundlers.
fix Consider migrating to the 'deassert' package for cross-bundler compatibility.
npm install rollup-plugin-deassert
yarn add rollup-plugin-deassert
pnpm add rollup-plugin-deassert

Example of using rollup-plugin-deassert in a Rollup config to strip assert statements from TypeScript files.

// rollup.config.js
import { rollupPlugin as deassert } from 'rollup-plugin-deassert';

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  plugins: [
    deassert({
      include: ['**/*.ts'],
      sourcemap: true
    })
  ]
};