Registry / devops / google-closure-compiler

google-closure-compiler

JSON →
library20260602.0.0jsnpmunverified

The Google Closure Compiler npm package (v20260602.0.0) provides the official Closure Compiler binary for JavaScript checking, optimization, and minification. Released monthly from the upstream Closure Compiler repository. It supports three execution modes: a native binary (Linux/macOS/Windows), a Java jar (requires Java), and an npx runner. Key differentiator: offers both simple and advanced compilation levels (including dead code elimination, type checking, and global renamings) unmatched by simpler minifiers like UglifyJS or Terser. It also includes Grunt and Gulp plugins, and an official webpack plugin. Note: the installed package contains a native binary or Java jar, not JavaScript. The Java version generally yields faster compilations for large projects.

npm install google-closure-compiler
INSTALL
IMPORT
SIG · GOOGLE-CLOSURE-COM
G
google-closure-compiler
devopsjavascriptv20260602.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import compiler from 'google-closure-compiler'
const compiler = require('google-closure-compiler')
Package is ESM-only since v20210601 (breaking change). Use dynamic import or ESM project. The default export is a function that returns a closure compiler instance.
compiler
import compiler from 'google-closure-compiler'; const cc = new compiler.compiler({ js: 'in.js', compilation_level: 'SIMPLE' })
const { compiler } = require('google-closure-compiler')
Named export 'compiler' is deprecated since v20220206. Use default import to get the Compiler class.
gulpPlugin
import gulpPlugin from 'google-closure-compiler/gulp'
const gulpPlugin = require('google-closure-compiler').gulp()
Gulp plugin is exported as default from 'google-closure-compiler/gulp'. CommonJS require pattern fails in ESM-only package.
gruntPlugin
import gruntPlugin from 'google-closure-compiler/grunt'
require('google-closure-compiler/grunt')
Grunt plugin is ESM-only. Import from subpath 'google-closure-compiler/grunt'.

Shows programmatic usage of the Closure Compiler with ESM import, basic compilation options, and async execution via promisify.

import compiler from 'google-closure-compiler'; import { promisify } from 'util'; const cc = new compiler.compiler({ js: 'input.js', compilation_level: 'ADVANCED_OPTIMIZATIONS', js_output_file: 'output.min.js' }); const run = promisify(cc.run.bind(cc)); run().then(() => console.log('Compilation completed')); // Or using npx: npx google-closure-compiler --js=input.js --js_output_file=output.min.js --compilation_level=ADVANCED
Debug
Known issues
breakingBreaking change: Package converted to ESM-only in v20210601. require() no longer works.
fix
Migrate to ESM imports. Use dynamic import() if needed in CommonJS project.
affects: >=20210601
deprecatedNamed export 'compiler' is deprecated since v20220206. Use default import instead.
fix
Replace import { compiler } with import compiler.
affects: >=20220206
breakingNative binary no longer ships as an optional dependency on some platforms; now requires explicit installation via @google-closure-compiler-linux-x64 etc.
fix
Install platform-specific package: npm install @google-closure-compiler-linux-x64
affects: >=20220206
gotchaBinary installed is not JavaScript; it's a native binary or Java jar. Using require() on the module will return an object, not execute the compiler.
fix
Use the compiler instance from the default export; do not attempt to require the binary path.
affects: all
gotchaGlob patterns may need quoting on Windows shells when using the Java version.
fix
Use double quotes around glob patterns in options object: js: '"src/**/*.js"'
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'google-closure-compiler'
Missing package installation or incorrect import path.
fix
Run npm install google-closure-compiler and ensure import path does not include subfolders (unless using plugin subpaths like /gulp).
TypeError: compiler.compiler is not a constructor
Using named import { compiler } which is deprecated; should use default import.
fix
Replace `import { compiler }` with `import compiler` and use new compiler.compiler().
Error: Cannot find module './out/Debug/compiler.jar'
Native binary/platform package not installed or incorrectly configured.
fix
Install the appropriate platform package: npm install @google-closure-compiler-linux-x64 (or -darwin-x64, -win32-x64).
Upgrade
Version history
20260602.0.0latest on npm
Audit
Dependencies
javaoptionalRequired for the Java jar version of the compiler; must be installed and in PATH.
Agent activity
4 hits · last 30 days
node
4
Resources
google-closure-compiler — npm install google-closure-compiler · libregistry