{"id":20194,"library":"loader-utils","title":"loader-utils","description":"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.","status":"active","version":"3.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/webpack/loader-utils","tags":["javascript"],"install":[{"cmd":"npm install loader-utils","lang":"bash","label":"npm"},{"cmd":"yarn add loader-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add loader-utils","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export; always import from the package root.","wrong":"const interpolateName = require('loader-utils/interpolateName')","symbol":"interpolateName","correct":"import { interpolateName } from 'loader-utils'"},{"note":"Named export, not default export.","wrong":"import urlToRequest from 'loader-utils'","symbol":"urlToRequest","correct":"import { urlToRequest } from 'loader-utils'"},{"note":"Can destructure but named import is fine.","wrong":"import * as loaderUtils from 'loader-utils'; const { getHashDigest } = loaderUtils","symbol":"getHashDigest","correct":"import { getHashDigest } from 'loader-utils'"}],"quickstart":{"code":"import { interpolateName, urlToRequest, isUrlRequest } from 'loader-utils';\n\nfunction myLoader(loaderContext, content) {\n  if (isUrlRequest(content)) {\n    const request = urlToRequest(content, '~');\n    // ...\n  }\n  const name = interpolateName(loaderContext, '[name].[contenthash:hex:8].[ext]', { content: Buffer.from(content) });\n  return name;\n}","lang":"javascript","description":"Demonstrates importing and using urlToRequest, isUrlRequest, and interpolateName in a webpack loader."},"warnings":[{"fix":"Upgrade to v2.0.4+ or v3.x.","message":"Prototype pollution vulnerability in versions <=2.0.2 and <=1.4.0. CVE-2022-37601.","severity":"breaking","affected_versions":"<=2.0.2 || <=1.4.0"},{"fix":"Upgrade to latest version in each major: v3.3.1, v2.0.4, v1.4.2.","message":"ReDoS vulnerability in versions <3.2.1, <2.0.4, <1.4.2.","severity":"breaking","affected_versions":"<3.2.1 || <2.0.4 || <1.4.2"},{"fix":"Replace getOptions calls with loaderContext.getOptions() or use webpack's built-in.","message":"getOptions has been deprecated in v3.x. Use loaderContext.getOptions() instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Replace parseQuery with new URLSearchParams(query).","message":"parseQuery has been deprecated. Use URLSearchParams or the standard query parser.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Specify hash type explicitly, e.g., [hash:md4:hex] for backward compatibility.","message":"interpolateName's [hash] uses xxhash64 by default in v3+. Previous versions used md4. This can cause unexpected hash output differences when upgrading.","severity":"gotcha","affected_versions":">=3.2.0"},{"fix":"Review usages where root parameter is passed to urlToRequest.","message":"urlToRequest with root starting with '~' now treats it as module request. Previously only URL starting with '~' was treated as module. Behavior changed subtly in v3.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use loaderContext.getOptions() instead.","cause":"getOptions was removed in v3.x.","error":"TypeError: loaderUtils.getOptions is not a function"},{"fix":"Remove the import; use built-in URL parser or query string splitting.","cause":"parseQuery is no longer exported in v3.x.","error":"Error: Cannot find module 'loader-utils/parseQuery'"},{"fix":"Use [fullhash] in webpack configuration for full chunk hash, or use [contenthash:xxhash64:hex] in loader-utils.","cause":"Using [contenthash] in webpack 5+ but loader-utils interpolateName uses its own hashing.","error":"Warning: [contenthash] is deprecated, use [fullhash] instead"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}