null-loader

raw JSON →
4.0.1 verified Sat Apr 25 auth: no javascript

A webpack loader that returns an empty module, useful for silencing unwanted imports (e.g., polyfills) in your bundle. Current stable version is 4.0.1 (released 2020-10-09), supporting webpack 4 and 5. Maintained under the webpack-contrib organization. Unlike other loaders, it provides a minimal no-op module instead of stripping imports entirely.

error Module not found: Error: Can't resolve 'null-loader' in '...'
cause null-loader is not installed or webpack cannot resolve it.
fix
Run npm install null-loader --save-dev and ensure node_modules path is correct.
error Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
cause Using null-loader with an unsupported option (e.g., `emitFile`).
fix
Remove the unknown option or upgrade null-loader to latest version.
error TypeError: this.getOptions is not a function
cause Using null-loader with webpack 3 or earlier.
fix
Upgrade to webpack 4+ or use null-loader@3 for webpack 3.
breaking v4.0.0 removed support for webpack <4 and dropped the deprecated `emitFile` option.
fix Upgrade webpack to 4+ and remove any use of `emitFile` option.
deprecated The 'emitFile' option was removed in v4.0.0. Use webpack module.exportPreservedModules instead.
fix Remove the 'emitFile' option from the loader configuration.
gotcha Using null-loader on every JS file will break your build because it replaces modules with empty objects.
fix Always scope null-loader to specific files using `test` or `include` in the rule.
gotcha null-loader does not preserve side effects; the replaced module is completely empty.
fix Ensure the module being nullified has no side effects required by your application.
npm install null-loader
yarn add null-loader
pnpm add null-loader

Basic webpack configuration to replace a polyfill module with an empty module using null-loader.

// webpack.config.js
const path = require('path');
module.exports = {
  module: {
    rules: [
      {
        test: path.resolve(__dirname, 'node_modules/some-polyfill/index.js'),
        use: 'null-loader',
      },
    ],
  },
};