Registry / devops / less-loader

less-loader

JSON →
library12.3.2jsnpmunverified

A webpack loader that compiles Less files into CSS. Current stable version is 12.3.2 (March 2026), with frequent releases addressing compatibility and bug fixes. Requires Node.js >=18.12.0 as of v12.0.0 (breaking change). Supports Less 3.x or 4.x, webpack 5, and optionally @rspack/core. Key differentiators: tight integration with webpack's module system, support for webpackImporter, and the ability to pass Less options dynamically via loader context.

npm install less-loader
INSTALL
IMPORT
SIG · LESS-LOADER
L
less-loader
devopsjavascriptv12.3.2
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 (loader)
module.exports = { module: { rules: [ { test: /\.less$/i, use: [ 'style-loader', 'css-loader', 'less-loader' ] } ] } }
const lessLoader = require('less-loader'); // Not a direct import; use as webpack loader in config
less-loader is used as a webpack loader, not imported directly in application code. It must be configured in webpack.config.js.
LessOptions
import type { LessOptions } from 'less'; // Or: type LessOptions = import('less').options
import { LessOptions } from 'less-loader'; // Not exported from less-loader
Type definitions for Less options come from the 'less' package, not less-loader.
LoaderContext
import type { LoaderContext } from 'webpack'; // Or: type LoaderContext = import('webpack').LoaderContext
import { LoaderContext } from 'less-loader'; // Not exported
Used for dynamic lessOptions function signature; imported from webpack.

Minimal webpack setup to compile a Less file to CSS using less-loader, style-loader, and css-loader.

// Install: npm install less less-loader style-loader css-loader --save-dev // webpack.config.js const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), }, module: { rules: [ { test: /\.less$/i, use: [ 'style-loader', // Inject CSS into DOM 'css-loader', // Resolve CSS imports 'less-loader', // Compile Less to CSS ], }, ], }, }; // src/style.less @primary-color: #333; body { color: @primary-color; } // src/index.js import './style.less'; console.log('Hello, world!');
Debug
Known issues
breakingNode.js version <18.12.0 is no longer supported
fix
Upgrade Node.js to >=18.12.0
affects: >=12.0.0
breakingwebpack 4 or earlier not supported; webpack 5 is required
fix
Upgrade webpack to ^5.0.0
affects: >=12.0.0
deprecatedThe plugin system for less-loader is deprecated; use options instead.
fix
Move custom logic to lessOptions or additionalData
affects: >=11.0.0
gotchasource maps may break if additionalData is used to prepend/append code
fix
Set devtool appropriately; consider using sourceMap: true in lessOptions
affects: >=1.0.0
gotchaSome Less options require camelCase; dash-case options are ignored
fix
Use camelCase keys in lessOptions (e.g., relativeUrls instead of relative-urls)
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'less'
Less is not installed or not in node_modules.
fix
npm install less --save-dev
ValidationError: Invalid options object. Less Loader has been initialized using an options object that does not match the API schema.
Options passed to less-loader are not valid (e.g., incorrect property name).
fix
Check options: valid properties are lessOptions, additionalData, sourceMap, webpackImporter, implementation, lessLogAsWarnOrErr.
Error: Cannot find module 'less-loader'
less-loader is not installed.
fix
npm install less less-loader --save-dev
TypeError: Cannot read properties of undefined (reading 'options')
Loader configuration may be incorrect; missing 'loader' property.
fix
Ensure use array entries are objects with 'loader' and 'options' keys: { loader: 'less-loader', options: { ... } }
Upgrade
Version history
12.3.2latest on npm
Audit
Dependencies
lessrequiredPeer dependency: the actual Less compiler that less-loader invokes.
webpackrequiredPeer dependency: webpack 5 is required as the bundler.
@rspack/coreoptionalOptional peer dependency for Rspack compatibility.
Agent activity
2 hits · last 30 days
node
2
Resources
less-loader — npm install less-loader · libregistry