Registry / devops / html-minifier-security-fix

html-minifier-security-fix

JSON →
library4.0.0jsnpmunverified

HTMLMinifier is a highly configurable, well-tested JavaScript-based HTML minifier. The current stable version is 4.0.0, released with few updates in recent years. It is one of the most widely used HTML minifiers for Node.js, offering extensive options to control minification behavior such as removing comments, collapsing whitespace, and minifying inline CSS/JS. It supports both CLI and programmatic usage, and is compatible with Node.js >=6. Key differentiators: comprehensive option set, active community, and integration with popular build tools.

npm install html-minifier-security-fix
INSTALL
IMPORT
SIG · HTML-MINIFIER-SECU
H
html-minifier-security-fix
devopsjavascriptv4.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

minify
import { minify } from 'html-minifier'
const minify = require('html-minifier').minify
Default import is not available; use named import in ESM or destructure in CJS.
default
import htmlMinifier from 'html-minifier'
const htmlMinifier = require('html-minifier')
No default export exists; use named imports like { minify }.
htmlminifier
const htmlminifier = require('html-minifier')
import htmlminifier from 'html-minifier'
CommonJS require returns the module object; ESM default import is undefined.

Demonstrates basic HTML minification with common options like collapsing whitespace and removing comments.

import { minify } from 'html-minifier'; const result = minify('<p> Hello, world! </p>', { removeAttributeQuotes: true, collapseWhitespace: true, removeComments: true, minifyCSS: true, minifyJS: true, }); console.log(result); // output: <p>Hello, world!</p>
Debug
Known issues
gotchaOriginal package has no security fix; use html-minifier-terser which includes patches.
fix
Replace 'html-minifier' with 'html-minifier-terser' in package.json and imports.
affects: >=4.0.0
breakingDropped support for Node.js <6 in version 4.0.0.
fix
Upgrade Node.js to version 6 or later.
affects: >=4.0.0
gotchaThe 'minify' function can throw on invalid HTML. Always wrap in try-catch.
fix
Use try { minify(html, options); } catch(e) { console.error(e); }
affects: >=1.0.0
gotchaOptions like 'minifyCSS' and 'minifyJS' are boolean by default but can be objects; false disables, true enables with defaults.
fix
Set minifyCSS: true or provide specific options object.
affects: >=3.0.0
gotchaThe package has native ES module support only since v4. CommonJS require works but ESM import requires named imports.
fix
Use import { minify } from 'html-minifier' instead of default import.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: htmlMinifier is not a function
Attempting to call the default export as a function, but no default export exists.
fix
Use import { minify } from 'html-minifier' or const { minify } = require('html-minifier').
Error: Cannot find module 'html-minifier'
Package not installed or misspelled.
fix
Run npm install html-minifier and check package.json.
SyntaxError: Unexpected token 'export'
Using ES module import syntax in a CommonJS environment without proper configuration.
fix
Add "type": "module" to package.json or use require().
TypeError: Cannot read property 'collapseWhitespace' of undefined
Options object is undefined or null.
fix
Pass an empty object {} as second argument to minify().
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
html-minifier-terseroptionalA fork with security fixes and ongoing maintenance; original package is in maintenance mode.
Agent activity
6 hits · last 30 days
node
6
Resources
html-minifier-security-fix — npm install html-minifier-security-fix · libregistry