{"id":25734,"library":"html-minifier-next","title":"html-minifier-next","description":"html-minifier-next v6.2.0 is a super-configurable, JavaScript-based HTML minifier that also handles in-document CSS, JavaScript, and SVG minification. It is the actively maintained successor of the now-unmaintained HTML Minifier Terser and original HTML Minifier by kangax. The library is optimized for speed, offers both CLI and Node.js API, supports preset configurations, and ships TypeScript definitions. It requires @swc/core as a peer dependency for JavaScript minification. Released with monthly cadence, it aims to be backwards-compatible with its predecessors while adding new features like zero-config mode and ignore-dir support.","status":"active","version":"6.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/j9t/html-minifier-next","tags":["javascript","cli","compress","compressor","css","html","htmlmin","js","typescript"],"install":[{"cmd":"npm install html-minifier-next","lang":"bash","label":"npm"},{"cmd":"yarn add html-minifier-next","lang":"bash","label":"yarn"},{"cmd":"pnpm add html-minifier-next","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for JavaScript minification (used as default JS minifier)","package":"@swc/core","optional":true}],"imports":[{"note":"ESM-only since v6; CommonJS require is not supported. Use dynamic import if needed: const { minify } = await import('html-minifier-next').","wrong":"const { minify } = require('html-minifier-next')","symbol":"minify","correct":"import { minify } from 'html-minifier-next'"},{"note":"This package only exports named exports; there is no default export. Using default import will result in 'undefined' at runtime.","wrong":"import minify from 'html-minifier-next'","symbol":"default (minify)","correct":"import { minify } from 'html-minifier-next'"},{"note":"TypeScript users: MinifyOptions is a type-only export. Use 'import type' to avoid bundling issues in some environments.","wrong":"import { MinifyOptions } from 'html-minifier-next'","symbol":"MinifyOptions type","correct":"import type { MinifyOptions } from 'html-minifier-next'"}],"quickstart":{"code":"import { minify } from 'html-minifier-next';\n\nconst html = `\n<!DOCTYPE html>\n<html>\n<head>\n  <title>Test</title>\n</head>\n<body>\n  <p>Hello World</p>\n</body>\n</html>`;\n\nconst options = {\n  collapseWhitespace: true,\n  removeComments: true,\n  minifyJS: true,\n  minifyCSS: true\n};\n\nconst result = minify(html, options);\nconsole.log(result);\n// Output: <!DOCTYPE html><html><head><title>Test</title></head><body><p>Hello World</p></body></html>","lang":"typescript","description":"Basic usage: minify HTML string with options to collapse whitespace, remove comments, and inline CSS/JS minification."},"warnings":[{"fix":"Use import { minify } from 'html-minifier-next' or dynamic import: const { minify } = await import('html-minifier-next').","message":"All CommonJS require() calls will throw an error. This package is ESM-only.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Install @swc/core as a dependency: npm install @swc/core. Alternatively, provide a custom minifyJS function.","message":"Setting minifyJS to true without installing @swc/core will cause the minifier to fall back to a no-op or throw an error depending on version.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Always pass a string: const result = minify(String(html), options).","message":"minify function expects a string input; if you pass a Buffer or other object, it may be coerced to string incorrectly or throw.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use absolute paths or ensure the config file is in the project root when running CLI.","message":"Configuration file paths are relative to the current working directory, not the file being processed.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Explicitly set desired options. Use preset='comprehensive' via CLI or configure options programmatically.","message":"The default values for options like 'collapseWhitespace' and 'removeComments' are false. If you expect aggressive minification without specifying options, results may be unexpected.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade Node.js to >=14.0.0 (recommended >=16.14 for full ESM support).","cause":"Using an older Node.js version (<14) that does not support optional chaining.","error":"SyntaxError: Unexpected token '?'"},{"fix":"Run 'npm install @swc/core' or set 'minifyJS: false'.","cause":"minifyJS option enabled but @swc/core peer dependency is not installed.","error":"Error: Cannot find module '@swc/core'"},{"fix":"Use 'import { minify } from 'html-minifier-next'' instead of 'import minify from ...'.","cause":"Incorrect import: using default import instead of named import.","error":"TypeError: html_minifier_next_1.minify is not a function"},{"fix":"Use absolute path or change working directory: --config-file ./config/html-minifier.json","cause":"Config file path is relative to cwd but file is in a different directory.","error":"Error: Config file 'html-minifier.json' not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}