{"id":22090,"library":"rollup-plugin-invariant","title":"rollup-plugin-invariant","description":"Rollup plugin that strips invariant(condition, message) calls in production builds. v0.9.2 (stable, infrequent releases). It transforms invariant calls into empty statements when process.env.NODE_ENV is 'production', removing both the condition evaluation and message string. Unlike general dead-code elimination, this plugin specifically targets the invariant pattern without relying on Terser or manual tree-shaking, ensuring zero runtime overhead in production. Works with rollup >=1.0 and ships TypeScript types.","status":"active","version":"0.9.2","language":"javascript","source_language":"en","source_url":"https://github.com/apollographql/invariant-packages","tags":["javascript","rollup","plugin","invariant","development","production","NODE_ENV","typescript"],"install":[{"cmd":"npm install rollup-plugin-invariant","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-invariant","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-invariant","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"used for creating filter function from include/exclude options","package":"@rollup/pluginutils","optional":false},{"reason":"peer dependency; the invariant package that provides the function to be stripped","package":"invariant","optional":false}],"imports":[{"note":"The package exports a single function; default import is correct. CJS require works but is not the recommended ES module syntax.","wrong":"const invariantPlugin = require('rollup-plugin-invariant')","symbol":"default","correct":"import invariantPlugin from 'rollup-plugin-invariant'"},{"note":"Named export does not exist; use default import.","wrong":"import { invariantPlugin } from 'rollup-plugin-invariant'","symbol":"invariantPlugin","correct":"import invariantPlugin from 'rollup-plugin-invariant'"},{"note":"You can rename the default import to any name; common is 'invariant' (unrelated to the 'invariant' package).","wrong":"import { default as invariantPlugin } from 'rollup-plugin-invariant'","symbol":"invariantPlugin (used in rollup.config)","correct":"import invariant from 'rollup-plugin-invariant'"}],"quickstart":{"code":"// rollup.config.js\nimport invariantPlugin from 'rollup-plugin-invariant';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [\n    invariantPlugin({\n      // Default: include all files\n      include: ['**/*.js'],\n      // Optionally exclude node_modules\n      exclude: ['node_modules/**'],\n      // Force production mode (default: process.env.NODE_ENV === 'production')\n      production: true\n    })\n  ]\n};","lang":"javascript","description":"Configures rollup-plugin-invariant in a rollup config, showing include/exclude options and production flag override."},"warnings":[{"fix":"Ensure you import invariant from 'invariant' (or '@apollo/query-planner' which re-exports it).","message":"Plugin only works with the 'invariant' package from npm; custom invariant functions are not stripped.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Prefer ES module output or test with CJS. Consider using @rollup/plugin-commonjs to convert dependencies.","message":"The plugin does not support CommonJS output (or only transforms ES modules?). Check compatibility with your output format.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Options are passed as object to the plugin function: invariantPlugin({ include: ... })","cause":"Using options 'include' and 'exclude' as top-level plugin options instead of nested under 'invariantPlugin'.","error":"Error: Unknown plugin options: include, exclude"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}