No Emit Webpack Plugin
raw JSON → 4.0.1 verified Fri May 01 auth: no javascript
A webpack plugin that prevents specified asset bundles from being emitted by the compiler. Version 4.0.1 supports webpack 5 and Node >= 10.13.0. Key differentiator: it removes output files (e.g., JavaScript stubs generated from CSS entry points) without affecting the compilation process. The plugin accepts a string or array of asset names to block. It is commonly used with MiniCssExtractPlugin to suppress unwanted JS output. The project has a slow release cadence (last release 2021). Webpack 4 users must pin to version 3.0.0.
Common errors
error Error: NoEmitPlugin is not a constructor ↓
cause Using destructured import in CommonJS (e.g., const { NoEmitPlugin } = require(...)) when the module exports a single default.
fix
Use const NoEmitPlugin = require('no-emit-webpack-plugin');
error TypeError: compilation.hooks is undefined ↓
cause Using version 4.x with Webpack 4, which does not have the new hooks API.
fix
Downgrade to no-emit-webpack-plugin@3.0.0 for Webpack 4.
Warnings
breaking Webpack 5 support requires version 4.x; Webpack 4 users must use version 3.0.0. ↓
fix Pin to 'no-emit-webpack-plugin@3.0.0' for Webpack 4 projects.
breaking Passing an empty array [] will cause the plugin to do nothing (no assets removed). ↓
fix Ensure array argument has at least one string element.
breaking Minimum Node.js version raised to 10.13.0 in v4.0.0. ↓
fix Upgrade Node.js to >=10.13.0 or use v3.0.0.
deprecated Using a non-string file name (e.g., number) will throw a validation error since v3.0.0. ↓
fix Always pass string or array of strings.
Install
npm install no-emit-webpack-plugin yarn add no-emit-webpack-plugin pnpm add no-emit-webpack-plugin Imports
- NoEmitPlugin wrong
const NoEmitPlugin = require('no-emit-webpack-plugin').defaultcorrectimport NoEmitPlugin from 'no-emit-webpack-plugin' - default wrong
const { NoEmitPlugin } = require('no-emit-webpack-plugin')correctconst NoEmitPlugin = require('no-emit-webpack-plugin') - NoEmitPlugin (type) wrong
import { NoEmitPlugin } from 'no-emit-webpack-plugin'correctimport type { NoEmitPlugin } from 'no-emit-webpack-plugin'
Quickstart
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const NoEmitPlugin = require('no-emit-webpack-plugin');
module.exports = {
entry: {
style: './src/style.css',
main: './src/main.js',
},
module: {
rules: [{
test: /\.css$/iu,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
}],
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].css' }),
new NoEmitPlugin('style.js'), // suppresses the JS stub for style.css
],
};