{"id":25079,"library":"closure-compiler-service","title":"closure-compiler-service","description":"A Node.js wrapper for the Google Closure Compiler Service API that compiles JavaScript remotely without a Java dependency. Current stable version is 0.6.1. Release cadence is low; the library is minimal and stable. Key differentiators: no Java runtime required unlike the official closure-compiler Java implementation, simple API with both command-line and programmatic usage. Alternatives include google-closure-compiler (Java-based) and terser.","status":"active","version":"0.6.1","language":"javascript","source_language":"en","source_url":"git://github.com/gavinhungry/closure-compiler-service","tags":["javascript","closure","compiler","compress","google","minify","service"],"install":[{"cmd":"npm install closure-compiler-service","lang":"bash","label":"npm"},{"cmd":"yarn add closure-compiler-service","lang":"bash","label":"yarn"},{"cmd":"pnpm add closure-compiler-service","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS require; no default ESM export provided.","symbol":"default","correct":"const ccs = require('closure-compiler-service')"},{"note":"Named export for the main compile function.","symbol":"compile","correct":"const { compile } = require('closure-compiler-service')"},{"note":"ESM import may fail if module is not ESM; use CommonJS or dynamic import.","wrong":"import ccs from 'closure-compiler-service'","symbol":"default (ESM)","correct":"import ccs from 'closure-compiler-service'"}],"quickstart":{"code":"const ccs = require('closure-compiler-service');\nconst fs = require('fs');\n\nconst input = fs.readFileSync('input.js', 'utf8');\nccs.compile(input, function(errs, warns, code) {\n  if (errs) {\n    console.error('Errors:', errs);\n    return;\n  }\n  console.log(code); // compiled minified code\n});\n\n// With options:\nccs.compile(input, {\n  compilation_level: 'ADVANCED_OPTIMIZATIONS'\n}, function(errs, warns, code) {\n  if (errs) {\n    console.error('Errors:', errs);\n    return;\n  }\n  console.log(code);\n});","lang":"javascript","description":"Minifies JavaScript via Google Closure Compiler Service API using both default and advanced options."},"warnings":[{"fix":"Leave output_format as 'json' or handle non-JSON response manually.","message":"Default options set output_format to 'json'; if changed to something else, the callback may receive unexpected data.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure js_code is a string or Buffer; use .toString() if needed.","message":"The compile function expects a String or Buffer; passing an object or other type may cause errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Wrap call in try-catch for network failures or use a timeout.","message":"Network errors (e.g., service unavailable) are not handled gracefully; errors from the API are passed to callback but connection failures may throw.","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":"Check internet connection or retry later.","cause":"Closure Compiler Service API endpoint unreachable due to network or server down.","error":"Error: connect ECONNREFUSED"},{"fix":"Convert input to a string or Buffer before passing.","cause":"js_code argument passed as object or number.","error":"TypeError: input is not a string or Buffer"},{"fix":"Use one of: 'WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'.","cause":"An unsupported compilation level string was passed.","error":"Error: Invalid compilation_level '...' provided"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}