{"id":41161,"library":"google-closure-compiler","title":"Google Closure Compiler","description":"The Google Closure Compiler npm package (v20260602.0.0) provides the official Closure Compiler binary for JavaScript checking, optimization, and minification. Released monthly from the upstream Closure Compiler repository. It supports three execution modes: a native binary (Linux/macOS/Windows), a Java jar (requires Java), and an npx runner. Key differentiator: offers both simple and advanced compilation levels (including dead code elimination, type checking, and global renamings) unmatched by simpler minifiers like UglifyJS or Terser. It also includes Grunt and Gulp plugins, and an official webpack plugin. Note: the installed package contains a native binary or Java jar, not JavaScript. The Java version generally yields faster compilations for large projects.","status":"active","version":"20260602.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ChadKillingsworth/closure-compiler-npm","tags":["javascript","compiler","optimizer","minifier","closure","gulpplugin","gruntplugin"],"install":[{"cmd":"npm install google-closure-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add google-closure-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add google-closure-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for the Java jar version of the compiler; must be installed and in PATH.","package":"java","optional":true}],"imports":[{"note":"Package is ESM-only since v20210601 (breaking change). Use dynamic import or ESM project. The default export is a function that returns a closure compiler instance.","wrong":"const compiler = require('google-closure-compiler')","symbol":"default","correct":"import compiler from 'google-closure-compiler'"},{"note":"Named export 'compiler' is deprecated since v20220206. Use default import to get the Compiler class.","wrong":"const { compiler } = require('google-closure-compiler')","symbol":"compiler","correct":"import compiler from 'google-closure-compiler';\nconst cc = new compiler.compiler({ js: 'in.js', compilation_level: 'SIMPLE' })"},{"note":"Gulp plugin is exported as default from 'google-closure-compiler/gulp'. CommonJS require pattern fails in ESM-only package.","wrong":"const gulpPlugin = require('google-closure-compiler').gulp()","symbol":"gulpPlugin","correct":"import gulpPlugin from 'google-closure-compiler/gulp'"},{"note":"Grunt plugin is ESM-only. Import from subpath 'google-closure-compiler/grunt'.","wrong":"require('google-closure-compiler/grunt')","symbol":"gruntPlugin","correct":"import gruntPlugin from 'google-closure-compiler/grunt'"}],"quickstart":{"code":"import compiler from 'google-closure-compiler';\nimport { promisify } from 'util';\n\nconst cc = new compiler.compiler({\n  js: 'input.js',\n  compilation_level: 'ADVANCED_OPTIMIZATIONS',\n  js_output_file: 'output.min.js'\n});\nconst run = promisify(cc.run.bind(cc));\nrun().then(() => console.log('Compilation completed'));\n// Or using npx: npx google-closure-compiler --js=input.js --js_output_file=output.min.js --compilation_level=ADVANCED","lang":"typescript","description":"Shows programmatic usage of the Closure Compiler with ESM import, basic compilation options, and async execution via promisify."},"warnings":[{"fix":"Migrate to ESM imports. Use dynamic import() if needed in CommonJS project.","message":"Breaking change: Package converted to ESM-only in v20210601. require() no longer works.","severity":"breaking","affected_versions":">=20210601"},{"fix":"Replace import { compiler } with import compiler.","message":"Named export 'compiler' is deprecated since v20220206. Use default import instead.","severity":"deprecated","affected_versions":">=20220206"},{"fix":"Install platform-specific package: npm install @google-closure-compiler-linux-x64","message":"Native binary no longer ships as an optional dependency on some platforms; now requires explicit installation via @google-closure-compiler-linux-x64 etc.","severity":"breaking","affected_versions":">=20220206"},{"fix":"Use the compiler instance from the default export; do not attempt to require the binary path.","message":"Binary installed is not JavaScript; it's a native binary or Java jar. Using require() on the module will return an object, not execute the compiler.","severity":"gotcha","affected_versions":"all"},{"fix":"Use double quotes around glob patterns in options object: js: '\"src/**/*.js\"'","message":"Glob patterns may need quoting on Windows shells when using the Java version.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'advanc':55 'also':76 'binari':16,38,94 'check':19,63 'closur':2,6,14,28,114 'code':60 'compil':3,7,15,29,56,106,111 'contain':91 'dead':59 'differenti':50 'elimin':61 'execut':34 'faster':105 'general':103 'global':65 'googl':1,5 'grunt':78 'gruntplugin':116 'gulp':80 'gulpplugin':115 'includ':58,77 'instal':89 'jar':42,97 'java':41,44,96,101 'javascript':18,99,110 'key':49 'larg':108 'level':57 'like':71 'linux/macos/windows':39 'minif':22 'minifi':70,113 'mode':35 'month':24 'nativ':37,93 'note':87 'npm':8 'npx':47 'offer':51 'offici':13,84 'optim':20,112 'packag':9,90 'plugin':81,86 'project':109 'provid':11 'releas':23 'renam':66 'repositori':30 'requir':43 'runner':48 'simpl':53 'simpler':69 'support':32 'terser':74 'three':33 'type':62 'uglifyj':72 'unmatch':67 'upstream':27 'v20260602.0.0':10 'version':102 'webpack':85 'yield':104","created_at":"2026-06-04T18:51:04.274952+00:00","updated_at":"2026-06-04T18:51:04.274952+00:00","problems":[{"fix":"Run npm install google-closure-compiler and ensure import path does not include subfolders (unless using plugin subpaths like /gulp).","cause":"Missing package installation or incorrect import path.","error":"Error: Cannot find module 'google-closure-compiler'"},{"fix":"Replace `import { compiler }` with `import compiler` and use new compiler.compiler().","cause":"Using named import { compiler } which is deprecated; should use default import.","error":"TypeError: compiler.compiler is not a constructor"},{"fix":"Install the appropriate platform package: npm install @google-closure-compiler-linux-x64 (or -darwin-x64, -win32-x64).","cause":"Native binary/platform package not installed or incorrectly configured.","error":"Error: Cannot find module './out/Debug/compiler.jar'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://developers.google.com/closure/compiler/","github":"https://github.com/ChadKillingsworth/closure-compiler-npm","docs":null,"changelog":null,"pypi":null,"npm":"google-closure-compiler","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}