google-closure-compiler-osx
raw JSON → 20240317.0.0 verified Fri May 01 auth: no javascript
The OS X native binary distribution of Google's Closure Compiler, a JavaScript optimization and type-checking tool. This package provides the compiler via a Java binary specifically for macOS. Current stable version: 20240317.0.0. Releases follow upstream Closure Compiler releases, typically monthly. This is the platform-specific variant for macOS; equivalent packages exist for linux, windows, and a Java-based generic one. Key differentiator: optimized native binary for macOS vs running via Java.
Common errors
error Error: Cannot find module 'google-closure-compiler-osx' ↓
cause Package not installed or not available on this platform
fix
Install with npm install google-closure-compiler-osx --save-dev
error Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.io.FileNotFoundException: /path/to/input.js ↓
cause Input file path is incorrect or missing
fix
Check that input file exists and path is absolute or correctly relative.
error WARNING: -Dfile.encoding=UTF-8 not supported ↓
cause Encoding flag not supported on native binary
fix
Remove the -Dfile.encoding=UTF-8 flag from your command.
Warnings
gotcha The native binary may require Rosetta 2 on Apple Silicon Macs for versions before 2023. ↓
fix Update to version >=20230501 or use the Java fallback via google-closure-compiler-java.
gotcha The package is platform-specific; installing on non-macOS will fail or fallback to Java. ↓
fix Use google-closure-compiler-linux or google-closure-compiler-windows for other platforms.
breaking Switched from bundled Java to native binary in v20201001. Old versions were Java-based requiring JRE. ↓
fix Upgrade to >=20201001 or ensure JRE is installed if using older versions.
Install
npm install google-closure-compiler-osx yarn add google-closure-compiler-osx pnpm add google-closure-compiler-osx Imports
- getNativeImagePath wrong
const getNativeImagePath = require('google-closure-compiler-osx').getNativeImagePathcorrectimport { getNativeImagePath } from 'google-closure-compiler-osx' - platform wrong
import platform from 'google-closure-compiler-osx'correctconst platform = require('google-closure-compiler-osx') - binaryPath
import { binaryPath } from 'google-closure-compiler-osx'
Quickstart
const { exec } = require('child_process');
const path = require('path');
const cc = require('google-closure-compiler-osx');
const compilerPath = cc.binaryPath;
// Compile a simple JavaScript file
const child = exec(`${compilerPath} --compilation_level SIMPLE_OPTIMIZATIONS --js input.js --js_output_file output.min.js`);
child.stdout.on('data', (data) => console.log(data));
child.stderr.on('data', (data) => console.error(data));