Registry / gcp / closure-compiler-service

closure-compiler-service

JSON →
library0.6.1jsnpmunverified

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.

npm install closure-compiler-service
INSTALL
IMPORT
SIG · CLOSURE-COMPILER-S
C
closure-compiler-service
gcpjavascriptv0.6.1
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
const ccs = require('closure-compiler-service')
CommonJS require; no default ESM export provided.
compile
const { compile } = require('closure-compiler-service')
Named export for the main compile function.
default (ESM)
import ccs from 'closure-compiler-service'
import ccs from 'closure-compiler-service'
ESM import may fail if module is not ESM; use CommonJS or dynamic import.

Minifies JavaScript via Google Closure Compiler Service API using both default and advanced options.

const ccs = require('closure-compiler-service'); const fs = require('fs'); const input = fs.readFileSync('input.js', 'utf8'); ccs.compile(input, function(errs, warns, code) { if (errs) { console.error('Errors:', errs); return; } console.log(code); // compiled minified code }); // With options: ccs.compile(input, { compilation_level: 'ADVANCED_OPTIMIZATIONS' }, function(errs, warns, code) { if (errs) { console.error('Errors:', errs); return; } console.log(code); });
closure-compiler --version
Debug
Known issues
gotchaDefault options set output_format to 'json'; if changed to something else, the callback may receive unexpected data.
fix
Leave output_format as 'json' or handle non-JSON response manually.
affects: >=0.0.0
gotchaThe compile function expects a String or Buffer; passing an object or other type may cause errors.
fix
Ensure js_code is a string or Buffer; use .toString() if needed.
affects: >=0.0.0
gotchaNetwork errors (e.g., service unavailable) are not handled gracefully; errors from the API are passed to callback but connection failures may throw.
fix
Wrap call in try-catch for network failures or use a timeout.
affects: >=0.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED
Closure Compiler Service API endpoint unreachable due to network or server down.
fix
Check internet connection or retry later.
TypeError: input is not a string or Buffer
js_code argument passed as object or number.
fix
Convert input to a string or Buffer before passing.
Error: Invalid compilation_level '...' provided
An unsupported compilation level string was passed.
fix
Use one of: 'WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'.
Upgrade
Version history
0.6.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
30
OpenAI (training)
1
Resources
closure-compiler-service — npm install closure-compiler-service · libregistry