{"id":41245,"library":"html-minifier-security-fix","title":"HTMLMinifier","description":"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.","status":"maintenance","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/kangax/html-minifier","tags":["javascript","cli","compress","compressor","css","html","htmlmin","min"],"install":[{"cmd":"npm install html-minifier-security-fix","lang":"bash","label":"npm"},{"cmd":"yarn add html-minifier-security-fix","lang":"bash","label":"yarn"},{"cmd":"pnpm add html-minifier-security-fix","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"A fork with security fixes and ongoing maintenance; original package is in maintenance mode.","package":"html-minifier-terser","optional":true}],"imports":[{"note":"Default import is not available; use named import in ESM or destructure in CJS.","wrong":"const minify = require('html-minifier').minify","symbol":"minify","correct":"import { minify } from 'html-minifier'"},{"note":"No default export exists; use named imports like { minify }.","wrong":"const htmlMinifier = require('html-minifier')","symbol":"default","correct":"import htmlMinifier from 'html-minifier'"},{"note":"CommonJS require returns the module object; ESM default import is undefined.","wrong":"import htmlminifier from 'html-minifier'","symbol":"htmlminifier","correct":"const htmlminifier = require('html-minifier')"}],"quickstart":{"code":"import { minify } from 'html-minifier';\n\nconst result = minify('<p>  Hello, world!  </p>', {\n  removeAttributeQuotes: true,\n  collapseWhitespace: true,\n  removeComments: true,\n  minifyCSS: true,\n  minifyJS: true,\n});\n\nconsole.log(result);\n// output: <p>Hello, world!</p>","lang":"javascript","description":"Demonstrates basic HTML minification with common options like collapsing whitespace and removing comments."},"warnings":[{"fix":"Replace 'html-minifier' with 'html-minifier-terser' in package.json and imports.","message":"Original package has no security fix; use html-minifier-terser which includes patches.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Upgrade Node.js to version 6 or later.","message":"Dropped support for Node.js <6 in version 4.0.0.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use try { minify(html, options); } catch(e) { console.error(e); }","message":"The 'minify' function can throw on invalid HTML. Always wrap in try-catch.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set minifyCSS: true or provide specific options object.","message":"Options like 'minifyCSS' and 'minifyJS' are boolean by default but can be objects; false disables, true enables with defaults.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use import { minify } from 'html-minifier' instead of default import.","message":"The package has native ES module support only since v4. CommonJS require works but ESM import requires named imports.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'4.0.0':20 '6':69 'activ':75 'base':12 'behavior':46 'build':81 'cli':60,84 'collaps':51 'comment':50 'communiti':76 'compat':66 'comprehens':72 'compress':85 'compressor':86 'configur':6 'control':44 'css':87 'css/js':56 'current':16 'differenti':71 'extens':41 'high':5 'html':13,36,88 'htmlmin':89 'htmlminifi':1,2 'inlin':55 'integr':78 'javascript':11,83 'javascript-bas':10 'key':70 'min':90 'minif':45 'minifi':14,37,54 'node.js':39,68 'offer':40 'one':30 'option':42,73 'popular':80 'programmat':62 'recent':26 'releas':21 'remov':49 'set':74 'stabl':17 'support':58 'test':9 'tool':82 'updat':24 'usag':63 'use':35 'version':18 'well':8 'well-test':7 'whitespac':52 'wide':34 'year':27","created_at":"2026-06-04T18:51:28.697185+00:00","updated_at":"2026-06-04T18:51:28.697185+00:00","problems":[{"fix":"Use import { minify } from 'html-minifier' or const { minify } = require('html-minifier').","cause":"Attempting to call the default export as a function, but no default export exists.","error":"TypeError: htmlMinifier is not a function"},{"fix":"Run npm install html-minifier and check package.json.","cause":"Package not installed or misspelled.","error":"Error: Cannot find module 'html-minifier'"},{"fix":"Add \"type\": \"module\" to package.json or use require().","cause":"Using ES module import syntax in a CommonJS environment without proper configuration.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Pass an empty object {} as second argument to minify().","cause":"Options object is undefined or null.","error":"TypeError: Cannot read property 'collapseWhitespace' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://kangax.github.io/html-minifier/","github":"https://github.com/kangax/html-minifier","docs":null,"changelog":null,"pypi":null,"npm":"html-minifier-security-fix","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}