node-minify

raw JSON →
3.6.0 verified Fri May 01 auth: no javascript

A modular JavaScript/TypeScript minification library supporting multiple compressors: Babel-minify, UglifyJS, Terser, Google Closure Compiler, Clean-css, CSSO, esbuild, and more. Current stable version is 10.5.0 (2025+). Released regularly with minor updates. Key differentiators: unified API for JS and CSS minifiers, works in Node.js (>=6) and browsers, ESM-only since v10, actively maintained with modern compressor support like esbuild and Lightning CSS. Also provides a CLI and image minification via imagemin.

error ERR_REQUIRE_ESM package '@node-minify/core' is ESM (ES Module) but your script is CommonJS
cause Using require() on an ESM-only package.
fix
Add 'type': 'module' to package.json or use import syntax.
error TypeError: minify is not a function
cause Importing default export instead of named export.
fix
import { minify } from '@node-minify/core' instead of import minify from '@node-minify/core'.
error Cannot find module '@node-minify/core'
cause Package not installed or wrong package name.
fix
npm install @node-minify/core.
error SyntaxError: Unexpected token 'export'
cause Using CommonJS syntax (require) for ESM package.
fix
Use import or enable ESM in your environment.
error Error: No such compressor: ...
cause Referencing a compressor not installed or incorrectly spelled.
fix
Install the appropriate @node-minify/* package and import the default export.
breaking v10 drops support for CommonJS (require). Only ESM imports are supported.
fix Switch to import syntax and ensure package.json has 'type': 'module'.
deprecated The 'node-minify' package (global) is deprecated; use @node-minify/* scoped packages.
fix Replace with @node-minify/core and specific compressor packages.
breaking Callback-based API removed in v9; use promises or async/await.
fix Use minify({...}) which returns a Promise.
gotcha Compressors are imported as default exports, not named exports.
fix Use 'import terser from '@node-minify/terser'', not '{ terser }'.
breaking v10 renames all packages to @node-minify scoped; old package names like 'node-minify' no longer publish.
fix Use @node-minify/core, @node-minify/terser, etc.
npm install node-minify
yarn add node-minify
pnpm add node-minify

Shows minification of JS using Terser and CSS using Clean-css with the core minify() function.

import { minify } from '@node-minify/core';
import terser from '@node-minify/terser';
import cleanCSS from '@node-minify/clean-css';

// Minify JavaScript with Terser
minify({
  compressor: terser,
  input: 'input.js',
  output: 'output.min.js',
  callback: (err, res) => {
    if (err) console.error(err);
    else console.log('JS minified successfully');
  }
});

// Minify CSS with Clean-css
minify({
  compressor: cleanCSS,
  input: 'styles.css',
  output: 'styles.min.css',
  callback: (err, res) => {
    if (err) console.error(err);
    else console.log('CSS minified successfully');
  }
});