{"id":25642,"library":"google-closure-compiler-java","title":"google-closure-compiler-java","description":"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.","status":"active","version":"20260428.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ChadKillingsworth/closure-compiler-npm","tags":["javascript","compiler","optimizer","minifier","closure","java"],"install":[{"cmd":"npm install google-closure-compiler-java","lang":"bash","label":"npm"},{"cmd":"yarn add google-closure-compiler-java","lang":"bash","label":"yarn"},{"cmd":"pnpm add google-closure-compiler-java","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Meta-package that includes platform-specific binaries; java package is a subset","package":"google-closure-compiler","optional":true}],"imports":[{"note":"ESM default export; in CJS use default property: const compiler = require(...).default","wrong":"const compiler = require('google-closure-compiler-java')","symbol":"default","correct":"import compiler from 'google-closure-compiler-java'"},{"note":"Exported function compile, not a class named Compiler","wrong":"import { Compiler } from 'google-closure-compiler-java'","symbol":"compile","correct":"import { compile } from 'google-closure-compiler-java'"},{"note":"Returns platform-specific Java path; not for native images in this package","wrong":null,"symbol":"getNativeImagePath","correct":"import { getNativeImagePath } from 'google-closure-compiler-java'"}],"quickstart":{"code":"import { compile } from 'google-closure-compiler-java';\nconst { code, warnings, errors } = compile({\n  jsCode: [{ src: 'function hello(name) { return \"Hello, \" + name; }' }],\n  compilationLevel: 'ADVANCED',\n  languageIn: 'ECMASCRIPT_2021',\n  languageOut: 'ECMASCRIPT5'\n});\nif (errors.length) {\n  console.error('Errors:', errors);\n} else {\n  console.log('Compiled JS:', code);\n}","lang":"typescript","description":"Demonstrates basic usage: compile a simple JavaScript string with advanced optimizations, handling errors."},"warnings":[{"fix":"Install Java Runtime Environment (JRE) 8+ and ensure java is on PATH.","message":"Requires Java 8 or later runtime installed; no bundled JRE.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use google-closure-compiler which includes platform-specific native images if Java not desired.","message":"The package does not include a Java binary; it only provides Node.js wrapper to invoke system Java. Misunderstanding expects bundled Java.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use in-memory compilation and write output manually if needed.","message":"The 'compile' function's 'jsOutputFile' property removed in v20221104 to discourage file system side effects.","severity":"deprecated","affected_versions":">=20221104.0.0"},{"fix":"Use exact values: 'WHITESPACE_ONLY', 'SIMPLE', 'ADVANCED'.","message":"compilationLevel must be a string matching Closure Compiler API; wrong case or misspelling fails silently.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always check result.errors array length before using result.code.","message":"Error handling: compile returns warnings and errors in result object; does not throw on compilation failure.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install Java 8+ (e.g., from adoptopenjdk.net) and ensure 'java -version' works in terminal.","cause":"Java runtime is not installed or not accessible on system PATH.","error":"Error: java not found. Please install Java and add it to your PATH."},{"fix":"Run 'npm install google-closure-compiler-java' and use correct import: import compiler from 'google-closure-compiler-java'.","cause":"Package not installed or import path wrong.","error":"Error: Cannot find module 'google-closure-compiler-java'"},{"fix":"Use import { compile } from 'google-closure-compiler-java' or import compiler from ... then compiler.compile().","cause":"Using default import but expecting compile function; default is the module namespace.","error":"TypeError: compiler is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}