Registry / devops / null-loader

null-loader

JSON →
library4.0.1jsnpmunverified

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.

npm install null-loader
INSTALL
IMPORT
SIG · NULL-LOADER
N
null-loader
devopsjavascriptv4.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = { module: { rules: [{ test: /polyfill\.js$/, use: 'null-loader' }] } }
import 'null-loader'
null-loader is a webpack loader, not a library; it is used in webpack config as a string reference.
NullLoader
const NullLoader = require('null-loader');
import NullLoader from 'null-loader';
While both require and import work in Node.js, webpack loader config traditionally uses require(). ESM import also works but is less common.
null-loader (as path)
use: require.resolve('null-loader')
use: require('null-loader')()
Do not invoke the loader function; pass the path or string name to 'use'. Using require.resolve() ensures correct path resolution.

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', }, ], }, };
Debug
Known issues
breakingv4.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.
affects: <4.0.0
deprecatedThe 'emitFile' option was removed in v4.0.0. Use webpack module.exportPreservedModules instead.
fix
Remove the 'emitFile' option from the loader configuration.
affects: >=4.0.0
gotchaUsing 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.
affects: >=0.0.0
gotchanull-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.
affects: >=0.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'null-loader' in '...'
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.
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
Using null-loader with an unsupported option (e.g., `emitFile`).
fix
Remove the unknown option or upgrade null-loader to latest version.
TypeError: this.getOptions is not a function
Using null-loader with webpack 3 or earlier.
fix
Upgrade to webpack 4+ or use null-loader@3 for webpack 3.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency; works with webpack 4 or 5
Agent activity
2 hits · last 30 days
node
2
Resources
null-loader — npm install null-loader · libregistry