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.
Common errors
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
Warnings
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
Install
npm install closurecompiler yarn add closurecompiler pnpm add closurecompiler Imports
- compile wrong
import ClosureCompiler from 'closurecompiler'correctvar ClosureCompiler = require('closurecompiler'); - ClosureCompiler.compile wrong
ClosureCompiler.compile(files, callback, options)correctClosureCompiler.compile(files, options, callback) - ccjs CLI wrong
ccjs sourceFiles... --js_output_file output.jscorrectccjs sourceFiles... [options] > output.js
Quickstart
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);
});