rollup-plugin-no-emit
raw JSON → 1.3.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that conditionally skips file emission during build. v1.3.0 supports Rollup 1.x through 4.x as peer dependencies and ships TypeScript typings. It provides a `match` function receiving the filename and output chunk/asset to decide which generated files to suppress. Unlike Rollup's built-in `output.preserveModules` or `output.emitFile` controls, this plugin gives fine-grained per-file filtering without altering bundle structure. The deprecated `RollupNoEmitOptions` interface has been replaced by `Options`. Simple API with two options: `emit` (boolean override) and `match` (predicate). No runtime dependencies.
Common errors
error Error: Rollup's generateBundle hook: Cannot read properties of null (reading 'fileName') ↓
cause match function called with undefined/null output chunk when output is not properly configured.
fix
Check that output.dir or output.file is set in Rollup config.
error TypeError: noEmit is not a function ↓
cause Importing the constructor function when using CommonJS require incorrectly: const noEmit = require('rollup-plugin-no-emit'); but actual export is an object with default.
fix
Use const noEmit = require('rollup-plugin-no-emit').default; or switch to ESM import.
error Error: Cannot find module 'rollup-plugin-no-emit' ↓
cause Package not installed.
fix
Run npm install --save-dev rollup-plugin-no-emit
error TS2304: Cannot find name 'Options' ↓
cause Imported Options as a value instead of type.
fix
Use import type { Options } from 'rollup-plugin-no-emit';
Warnings
deprecated RollupNoEmitOptions interface is deprecated; use Options instead. ↓
fix Replace type references from RollupNoEmitOptions to Options.
breaking In v1.0.0, match function signature changed to include second parameter (output: OutputChunk | OutputAsset). ↓
fix Update match callback to accept the new signature: (fileName, output) => boolean.
gotcha Plugin only works in the generateBundle hook; output must be defined. ↓
fix Ensure Rollup configuration has output specified.
gotcha Using noEmit with output.preserveModules or manualChunks may lead to unexpected behavior as the plugin suppresses files after chunking. ↓
fix Test match conditions thoroughly when combining with other output options.
Install
npm install rollup-plugin-no-emit yarn add rollup-plugin-no-emit pnpm add rollup-plugin-no-emit Imports
- default (noEmit) wrong
const noEmit = require('rollup-plugin-no-emit')correctimport noEmit from 'rollup-plugin-no-emit' - noEmit (named) wrong
import noEmit from 'rollup-plugin-no-emit'correctimport { noEmit } from 'rollup-plugin-no-emit' - Options wrong
import { Options } from 'rollup-plugin-no-emit'correctimport type { Options } from 'rollup-plugin-no-emit' - RollupNoEmitOptions (deprecated)
import type { RollupNoEmitOptions } from 'rollup-plugin-no-emit'
Quickstart
import noEmit from 'rollup-plugin-no-emit';
export default {
input: 'src/index.js',
output: { dir: 'dist' },
plugins: [
noEmit({
match: (fileName, output) => fileName === 'index.js' && output.type === 'chunk'
})
]
};