Registry / devops / loader-utils

loader-utils

JSON →
library3.3.1jsnpmunverified

Utility library for webpack loaders providing functions like urlToRequest, interpolateName, getHashDigest, and isUrlRequest. Version 3.3.1 is current stable, with ongoing maintenance from webpack. Key differentiators: it's the official utility set for webpack loader authors, handling URL resolution, filename templating with hashing (supports xxhash64, sha1, sha256, sha512, md4, md5), and multiple digest formats including hex, base26, base32, base36, base49, base52, base58, base62, base64, and base64safe. Compared to similar utilities, it integrates directly with webpack's loader context.

npm install loader-utils
INSTALL
IMPORT
SIG · LOADER-UTILS
L
loader-utils
devopsjavascriptv3.3.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.

interpolateName
import { interpolateName } from 'loader-utils'
const interpolateName = require('loader-utils/interpolateName')
Named export; always import from the package root.
urlToRequest
import { urlToRequest } from 'loader-utils'
import urlToRequest from 'loader-utils'
Named export, not default export.
getHashDigest
import { getHashDigest } from 'loader-utils'
import * as loaderUtils from 'loader-utils'; const { getHashDigest } = loaderUtils
Can destructure but named import is fine.

Demonstrates importing and using urlToRequest, isUrlRequest, and interpolateName in a webpack loader.

import { interpolateName, urlToRequest, isUrlRequest } from 'loader-utils'; function myLoader(loaderContext, content) { if (isUrlRequest(content)) { const request = urlToRequest(content, '~'); // ... } const name = interpolateName(loaderContext, '[name].[contenthash:hex:8].[ext]', { content: Buffer.from(content) }); return name; }
Debug
Known issues
breakingPrototype pollution vulnerability in versions <=2.0.2 and <=1.4.0. CVE-2022-37601.
fix
Upgrade to v2.0.4+ or v3.x.
affects: <=2.0.2 || <=1.4.0
breakingReDoS vulnerability in versions <3.2.1, <2.0.4, <1.4.2.
fix
Upgrade to latest version in each major: v3.3.1, v2.0.4, v1.4.2.
affects: <3.2.1 || <2.0.4 || <1.4.2
deprecatedgetOptions has been deprecated in v3.x. Use loaderContext.getOptions() instead.
fix
Replace getOptions calls with loaderContext.getOptions() or use webpack's built-in.
affects: >=3.0.0
deprecatedparseQuery has been deprecated. Use URLSearchParams or the standard query parser.
fix
Replace parseQuery with new URLSearchParams(query).
affects: >=3.0.0
gotchainterpolateName's [hash] uses xxhash64 by default in v3+. Previous versions used md4. This can cause unexpected hash output differences when upgrading.
fix
Specify hash type explicitly, e.g., [hash:md4:hex] for backward compatibility.
affects: >=3.2.0
gotchaurlToRequest with root starting with '~' now treats it as module request. Previously only URL starting with '~' was treated as module. Behavior changed subtly in v3.
fix
Review usages where root parameter is passed to urlToRequest.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: loaderUtils.getOptions is not a function
getOptions was removed in v3.x.
fix
Use loaderContext.getOptions() instead.
Error: Cannot find module 'loader-utils/parseQuery'
parseQuery is no longer exported in v3.x.
fix
Remove the import; use built-in URL parser or query string splitting.
Warning: [contenthash] is deprecated, use [fullhash] instead
Using [contenthash] in webpack 5+ but loader-utils interpolateName uses its own hashing.
fix
Use [fullhash] in webpack configuration for full chunk hash, or use [contenthash:xxhash64:hex] in loader-utils.
Upgrade
Version history
3.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources