ClosureCompiler.js

raw JSON →
1.6.1 verified Fri May 01 auth: no javascript deprecated

A Node.js wrapper for Google Closure Compiler that automatically downloads and sets up a JRE (from OpenJDK) and the compiler JAR. Version 1.6.1 (circa 2015) is the last stable release. This project is **deprecated** and no longer maintained; users should migrate to google-closure-compiler or google-closure-compiler-js. Key differentiator: self-contained (bundles JRE), but outdated compared to official or Java-free alternatives.

error Error: Could not find any Java installation
cause No JRE/JDK installed and automatic download failed
fix
Install Java or ensure JAVA_HOME is set
error FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed
cause Out of memory during compilation of large codebase
fix
Increase JVM heap via options: -xmx2048m
error Error: spawn ENOENT
cause ccjs command not found or Java not available
fix
Install globally with -g or check Java installation
deprecated This package is deprecated. Alternatives: google-closure-compiler, google-closure-compiler-js
fix Migrate to google-closure-compiler or google-closure-compiler-js
gotcha Requires Java runtime; if JRE not found, package may download a bundled OpenJDK ~45MB
fix Install Java beforehand to avoid the download
gotcha Options are case-insensitive in the API but must be snake_case (not camelCase)
fix Use compilation_level instead of compilationLevel
gotcha The --js_output_file flag is NOT supported; use shell redirection
fix Redirect stdout to file: ccjs files > output.js
npm install closurecompiler
yarn add closurecompiler
pnpm add closurecompiler

Demonstrates basic usage: compile a JavaScript file with advanced optimizations and Node.js externs.

var ClosureCompiler = require('closurecompiler');
ClosureCompiler.compile(['input.js'], {
    compilation_level: 'ADVANCED_OPTIMIZATIONS',
    warning_level: 'VERBOSE',
    externs: ['node']
}, function(err, result) {
    if (err) console.error(err);
    else console.log(result);
});