Registry / devops / google-closure-compiler-java

google-closure-compiler-java

JSON →
library20260428.0.0jsnpmunverified

Java platform distribution of Google's Closure Compiler, a JavaScript optimizer and minifier that produces highly efficient code. This package wraps the Closure Compiler Java library for use in Node.js environments. Current stable version is 20260428.0.0, released weekly alongside upstream Closure Compiler versions. Key differentiators: full Closure Compiler functionality (type checking, optimization, dead code elimination) via Java runtime; suitable for build pipelines; no GraalVM native-image dependency unlike the native platform packages. Compares to other minifiers (Terser, UglifyJS) by offering advanced compilation passes, strict type checking, and cross-module optimization.

npm install google-closure-compiler-java
INSTALL
IMPORT
SIG · GOOGLE-CLOSURE-COM
G
google-closure-compiler-java
devopsjavascriptv20260428.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-java'
const compiler = require('google-closure-compiler-java')
ESM default export; in CJS use default property: const compiler = require(...).default
compile
import { compile } from 'google-closure-compiler-java'
import { Compiler } from 'google-closure-compiler-java'
Exported function compile, not a class named Compiler
getNativeImagePath
import { getNativeImagePath } from 'google-closure-compiler-java'
Returns platform-specific Java path; not for native images in this package

Demonstrates basic usage: compile a simple JavaScript string with advanced optimizations, handling errors.

import { compile } from 'google-closure-compiler-java'; const { code, warnings, errors } = compile({ jsCode: [{ src: 'function hello(name) { return "Hello, " + name; }' }], compilationLevel: 'ADVANCED', languageIn: 'ECMASCRIPT_2021', languageOut: 'ECMASCRIPT5' }); if (errors.length) { console.error('Errors:', errors); } else { console.log('Compiled JS:', code); }
closure-compiler --version
Debug
Known issues
breakingRequires Java 8 or later runtime installed; no bundled JRE.
fix
Install Java Runtime Environment (JRE) 8+ and ensure java is on PATH.
affects: >=0.0.0
gotchaThe package does not include a Java binary; it only provides Node.js wrapper to invoke system Java. Misunderstanding expects bundled Java.
fix
Use google-closure-compiler which includes platform-specific native images if Java not desired.
affects: >=0.0.0
deprecatedThe 'compile' function's 'jsOutputFile' property removed in v20221104 to discourage file system side effects.
fix
Use in-memory compilation and write output manually if needed.
affects: >=20221104.0.0
gotchacompilationLevel must be a string matching Closure Compiler API; wrong case or misspelling fails silently.
fix
Use exact values: 'WHITESPACE_ONLY', 'SIMPLE', 'ADVANCED'.
affects: >=0.0.0
gotchaError handling: compile returns warnings and errors in result object; does not throw on compilation failure.
fix
Always check result.errors array length before using result.code.
affects: >=0.0.0
Errors
Common errors & fixes
Error: java not found. Please install Java and add it to your PATH.
Java runtime is not installed or not accessible on system PATH.
fix
Install Java 8+ (e.g., from adoptopenjdk.net) and ensure 'java -version' works in terminal.
Error: Cannot find module 'google-closure-compiler-java'
Package not installed or import path wrong.
fix
Run 'npm install google-closure-compiler-java' and use correct import: import compiler from 'google-closure-compiler-java'.
TypeError: compiler is not a function
Using default import but expecting compile function; default is the module namespace.
fix
Use import { compile } from 'google-closure-compiler-java' or import compiler from ... then compiler.compile().
Upgrade
Version history
20260428.0.0latest on npm
Audit
Dependencies
google-closure-compileroptionalMeta-package that includes platform-specific binaries; java package is a subset
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
google-closure-compiler-java — npm install google-closure-compiler-java · libregistry