{"id":25078,"library":"closure-calculate-chunks","title":"closure-calculate-chunks","description":"A utility to parse JavaScript files, resolve dependencies using Node module resolution, and produce Closure Compiler chunk and file definitions based on dynamic import split points. Version 3.2.2 is the current stable release, with irregular releases. It differs from other bundlers by directly targeting Google Closure Compiler's chunk API, supporting Closure-Library style goog.provide/goog.require dependencies, and providing a visualization mode for dependency graphs. It outputs JSON for use with closure-compiler --chunk and --js flags.","status":"active","version":"3.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/ChadKillingsworth/closure-calculate-chunks","tags":["javascript"],"install":[{"cmd":"npm install closure-calculate-chunks","lang":"bash","label":"npm"},{"cmd":"yarn add closure-calculate-chunks","lang":"bash","label":"yarn"},{"cmd":"pnpm add closure-calculate-chunks","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for directory climbing when resolving package.json files.","package":"escalade","optional":false},{"reason":"Used to resolve package exports maps.","package":"resolve-pkg-maps","optional":false},{"reason":"Used to resolve TypeScript config files.","package":"get-tsconfig","optional":false}],"imports":[{"note":"The package is ESM-only and does not support require() by default.","wrong":"const calculateChunks = require('closure-calculate-chunks')","symbol":"default","correct":"import calculateChunks from 'closure-calculate-chunks'"},{"note":"The default export is a function; there is no named export 'calculateChunks'.","wrong":"import { calculateChunks } from 'closure-calculate-chunks'","symbol":"calculateChunks","correct":"import calculateChunks from 'closure-calculate-chunks'"},{"note":"TypeScript types are exported from a separate path; check package.json exports.","wrong":"","symbol":"types","correct":"import type { Options } from 'closure-calculate-chunks'"}],"quickstart":{"code":"import calculateChunks from 'closure-calculate-chunks';\n\nconst result = await calculateChunks({\n  entrypoint: ['./src/js/entry.js'],\n  manualEntrypoints: ['chunkName:./src/js/extra.js'],\n  closureLibraryBaseJsPath: './node_modules/google-closure-library/closure/goog/base.js',\n  depsFiles: ['./deps.js'],\n  extraDeps: ['my.namespace:./src/ns.js'],\n  packageJsonEntryNames: ['module', 'main'],\n  namingStyle: 'entrypoint',\n  namePrefix: ''\n});\n\nconsole.log(JSON.stringify(result));","lang":"typescript","description":"Shows building a chunk definition programmatically with all available options."},"warnings":[{"fix":"Upgrade to 3.2.2 and adjust code to expect the new JSON structure with 'chunk' array containing strings, not objects.","message":"Version 3.x changed the output format of the CLI and programmatic API.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update Node.js to 14 or later.","message":"Requires Node >=14.0.0 as of version 3.0.0.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use import syntax instead of require(). For CommonJS projects, use dynamic import() or migrate to ESM.","message":"Switched from CommonJS to ESM-only in version 3.0.0.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use --extra-deps for individual namespaces instead of relying on base.js.","message":"The --closure-library-base-js-path flag may be deprecated in future versions as Closure Library usage declines.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use dynamic import('closure-calculate-chunks') or convert your project to ESM.","cause":"The package is ESM-only and cannot be required with CommonJS require().","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/closure-calculate-chunks/index.js from /path/to/your.js not supported."},{"fix":"Use: import calculateChunks from 'closure-calculate-chunks'","cause":"Importing as a named export instead of default export.","error":"TypeError: calculateChunks is not a function"},{"fix":"Update Node to >=14.0.0.","cause":"The package uses ESM syntax but your Node version is older than 12.22.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}