{"id":25075,"library":"clean-css","title":"clean-css","description":"A well-tested, fast and efficient CSS minifier for Node.js and browsers. Version 5.3.3 (stable) is released with patch updates over v5.3 (latest major). Clean-css outperforms many alternatives (cssnano, csso) in benchmarks, offering fine-grained optimization levels (0-2), compatibility modes (IE, standards), and source map support. It uses a highly modular plugin system and supports CLI, JavaScript API, and streaming. Engines require Node >= 10.0.","status":"active","version":"5.3.3","language":"javascript","source_language":"en","source_url":"https://github.com/clean-css/clean-css","tags":["javascript","css","minifier"],"install":[{"cmd":"npm install clean-css","lang":"bash","label":"npm"},{"cmd":"yarn add clean-css","lang":"bash","label":"yarn"},{"cmd":"pnpm add clean-css","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Source map generation requires the source-map module. Optional if source maps not needed.","package":"source-map","optional":true}],"imports":[{"note":"The library exports a default class; named import does not work. For CommonJS: const CleanCSS = require('clean-css').","wrong":"import { CleanCSS } from 'clean-css'","symbol":"CleanCSS","correct":"import CleanCSS from 'clean-css'"},{"note":"Default export. Destructuring from require is incorrect.","wrong":"const { CleanCSS } = require('clean-css')","symbol":"CleanCSS (CommonJS)","correct":"const CleanCSS = require('clean-css')"},{"note":"minify() is an instance method, not static.","wrong":"CleanCSS.minify(input, options)","symbol":"minify","correct":"const CleanCSS = require('clean-css'); const output = new CleanCSS(options).minify(input)"}],"quickstart":{"code":"const CleanCSS = require('clean-css');\nconst input = `body { font-size: 16px; color: red; }`;\nconst options = { level: 2 };\nconst output = new CleanCSS(options).minify(input);\nconsole.log(output.styles);\n// Expected: \"body{font-size:16px;color:red}\"","lang":"javascript","description":"Basic usage: instantiate CleanCSS with options, call minify() on a CSS string, and log the minified output."},"warnings":[{"fix":"Use dynamic import or ensure package is CJS-compatible. For v5, CommonJS require still works, but future versions may drop it.","message":"Switched to ES module exports. CommonJS require() no longer works.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Check output.styles instead of output.minified; errors in output.errors array.","message":"Return type changed from object with .styles to object with .styles (removed .sourceMap, .errors, .warnings in same object).","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Set options.returnPromise = true and await the call.","message":"minify() is synchronous. For large files, use Promise interface with .minify() returns a Promise if option 'returnPromise' is true.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use level 1's variableValueOptimizers option to enable variable optimization.","message":"CSS custom properties (variables) not optimized by default.","severity":"gotcha","affected_versions":"<5.3.0"},{"fix":"Set options.level[2].mergeMedia = true to restore old behavior.","message":"Level 2 optimizations no longer merge selectors from different media queries by default.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use Level 2 'restructureRules' or 'mergeSemantically' options (check docs).","message":"Semantic merge option removed.","severity":"deprecated","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install clean-css' and use 'require('clean-css')' or 'import CleanCSS from 'clean-css''.","cause":"clean-css not installed or incorrect import path.","error":"Cannot find module 'clean-css'"},{"fix":"Use 'import CleanCSS from 'clean-css'' or CommonJS require.","cause":"Using import { CleanCSS } instead of import CleanCSS (default import).","error":"CleanCSS is not a constructor"},{"fix":"Access 'output.styles' instead of 'output.minified'.","cause":"In v5+, output object key is 'styles' not 'minified'.","error":"output.minified is undefined"},{"fix":"Call minify on a valid CSS string; check output.errors for details.","cause":"minify() might have thrown error or invalid input.","error":"TypeError: Cannot read property 'styles' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}