{"id":10958,"library":"google-closure-library","title":"Google Closure Library","description":"Google Closure Library is a comprehensive, low-level JavaScript library developed by Google for building complex, highly performant, and scalable web applications. It serves as the foundation for many of Google's own web properties, including Gmail, Google Docs, and Google Maps. The library is not a typical npm package with standard ES module exports but rather provides its own module system (`goog.require`, `goog.provide`) built around a global `goog` object. It ships with a vast array of utilities covering DOM manipulation, UI components, networking, internationalization, data structures, and more. The current stable version is 20230802.0.0, and it follows a roughly monthly to bi-monthly release cadence, providing continuous updates and improvements, often tied to internal Google development cycles. Its key differentiators include its robust type system (when used with Closure Compiler), extensive cross-browser compatibility layers, and a strong emphasis on performance and security, making it suitable for large-scale enterprise applications.","status":"active","version":"20230802.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/google/closure-library","tags":["javascript","library","goog","closure"],"install":[{"cmd":"npm install google-closure-library","lang":"bash","label":"npm"},{"cmd":"yarn add google-closure-library","lang":"bash","label":"yarn"},{"cmd":"pnpm add google-closure-library","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"In Node.js, `google-closure-library` is primarily consumed by requiring the package, which sets up the global `goog` object and its module system. Direct ES module imports for the `goog` object itself are not supported.","wrong":"import goog from 'google-closure-library';","symbol":"goog","correct":"require('google-closure-library');"},{"note":"Closure Library components are exposed through the `goog.require` mechanism after the base library has been loaded. They are not designed for direct file-path based ES module or CommonJS imports.","wrong":"import { Sha1 } from 'google-closure-library/goog/crypt/sha1';","symbol":"goog.crypt.Sha1","correct":"require('google-closure-library');\ngoog.require('goog.crypt.Sha1');"},{"note":"Accessing specific Closure Library components requires using `goog.require` after initializing the library. Attempting to directly CommonJS `require` internal paths will fail as they rely on the Closure compiler's dependency management.","wrong":"const Dialog = require('google-closure-library/goog/ui/dialog');","symbol":"goog.ui.Dialog","correct":"require('google-closure-library');\ngoog.require('goog.ui.Dialog');"}],"quickstart":{"code":"require('google-closure-library');\n\ngoog.require('goog.crypt.Sha1');\ngoog.require('goog.array');\n\nconst sha1 = new goog.crypt.Sha1();\nconst data = 'Hello, Closure Library!';\nsha1.update(data);\nconst hash = sha1.digest();\n\nconsole.log(`SHA-1 hash of '${data}': ${goog.array.map(hash, byte => byte.toString(16).padStart(2, '0')).join('')}`);\n\n// Example of a utility that might not be available directly in Node.js\n// goog.require('goog.dom');\n// console.log(goog.dom.getWindow()); // This would typically only work in a browser environment","lang":"javascript","description":"This quickstart demonstrates how to initialize Closure Library in a Node.js environment, load specific components using `goog.require`, and use them to perform a SHA-1 hash operation."},"warnings":[{"fix":"Migrate to a downleveling development server (e.g., using Babel or TypeScript compilation) for transpilation during development. Do not rely on the Closure Library's debug loader for this functionality.","message":"The debug loader no longer downlevels sources in the browser, and `transpile.js` has been deleted. This affects development workflows that relied on in-browser transpilation.","severity":"breaking","affected_versions":">=20220803"},{"fix":"Ensure your target browsers exclude IE10. Applications requiring IE10 compatibility should stick to older versions of Closure Library or implement polyfills independently.","message":"Support for Internet Explorer 10 (IE10) has been officially dropped.","severity":"breaking","affected_versions":">=20221102"},{"fix":"It is strongly recommended to use a dedicated and secure templating system like Lit or an alternative approach that avoids direct string concatenation for HTML generation. Review and update existing code to use safer alternatives.","message":"`SafeHtml.create`, `SafeHtml.createScript`, `SafeHtml.setObjectData`, and `SafeHtml.setFrameSrc` methods are deprecated due to security considerations and to encourage safer templating practices.","severity":"deprecated","affected_versions":">=20221102"},{"fix":"Update delegate helper method calls to no longer pass the `defaultImpl` parameter. Review the Closure Library documentation for updated usage patterns.","message":"The `defaultImpl` parameter has been removed from Closure Delegates helper methods, which may break existing delegate implementations.","severity":"breaking","affected_versions":">=20230228"},{"fix":"Instead of direct constructor calls, use static factory methods or other provided mechanisms to create instances of `closure/html` types. Refer to the specific API documentation for the correct instantiation patterns.","message":"The `closure/html` types' constructors have been made private, preventing direct instantiation.","severity":"breaking","affected_versions":">=20230502"},{"fix":"Directly assign to `imageElement.src` instead: `imageElement.src = url;`.","message":"`goog.dom.safe.setImageSrc` has been deleted.","severity":"deprecated","affected_versions":">=20220905"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"In Node.js, ensure you have `require('google-closure-library');` at the top of your script. In a browser, ensure `base.js` is loaded via a `<script>` tag before any code that uses `goog`.","cause":"The base Closure Library file (and thus the global `goog` object) has not been loaded or initialized.","error":"ReferenceError: goog is not defined"},{"fix":"Verify the component name and path. Ensure `goog.require('goog.some.Component');` is called before attempting to use the component. If using the Closure Compiler, ensure the component is part of your compiled output.","cause":"The specified Closure Library component has not been loaded using `goog.require`, or there's a typo in the component path, or the component doesn't exist.","error":"Error: 'goog.some.Component' not found"},{"fix":"Use the Closure Library's native `goog.require()` system after loading the base library via CommonJS `require('google-closure-library');` in Node.js, or a script tag for `base.js` in browsers.","cause":"Attempting to use ES module `import` syntax with Closure Library components, which are not exposed as standard ES modules.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}