{"id":25080,"library":"closure-compiler","title":"closure-compiler","description":"Node.js wrapper for Google's Closure Compiler Java tool. v0.2.12 – stable but infrequent releases, last updated 2019. Runs the Closure Compiler JAR in a child process and returns compiled JavaScript via callback. Provides a simple API for advanced compilation and dead code elimination, but requires Java runtime. Alternatives like google-closure-compiler offer more frequent updates.","status":"maintenance","version":"0.2.12","language":"javascript","source_language":"en","source_url":"git://github.com/tim-smart/node-closure","tags":["javascript"],"install":[{"cmd":"npm install closure-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add closure-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add closure-compiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export, not default.","wrong":"const cc = require('closure-compiler'); cc.compile()","symbol":"compile","correct":"import { compile } from 'closure-compiler'"},{"note":"No default export; use namespace import for require style.","wrong":"import cc from 'closure-compiler'","symbol":"default (whole module)","correct":"import * as cc from 'closure-compiler'"},{"note":"Required as property destructure.","wrong":"const compile = require('closure-compiler')","symbol":"compile","correct":"const { compile } = require('closure-compiler')"}],"quickstart":{"code":"import { compile } from 'closure-compiler';\nimport { readFileSync } from 'fs';\n\nconst code = readFileSync('input.js', 'utf8');\ncompile(code, { compilation_level: 'ADVANCED_OPTIMIZATIONS' }, (err, stdout, stderr) => {\n  if (err) {\n    console.error('Compilation error:', stderr);\n    process.exit(1);\n  }\n  console.log(stdout);\n});","lang":"javascript","description":"Compile a JavaScript file with advanced optimizations using Closure Compiler asynchronously."},"warnings":[{"fix":"Install Java Runtime Environment (JRE) and ensure java is in PATH.","message":"Requires Java installed on PATH to run the Closure Compiler JAR.","severity":"gotcha","affected_versions":"all"},{"fix":"Wrap compile() in a Promise manually or use a wrapper.","message":"This package uses callbacks; no Promise support natively.","severity":"deprecated","affected_versions":"<0.3"},{"fix":"For array options, set as array in options object; the wrapper handles repetition.","message":"Options are passed as command-line flags; array values become repeated flags.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure java is installed and closure-compiler.jar is bundled.","cause":"Closure Compiler JAR not found or Java not installed.","error":"Error: Command failed: java -jar <path> ... exit code 1"},{"fix":"Use named import: import { compile } from 'closure-compiler'","cause":"Incorrect import of default vs named export.","error":"TypeError: compile is not a function"},{"fix":"Run npm install closure-compiler","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'closure-compiler'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}