{"id":25635,"library":"globalize-compiler","title":"globalize-compiler","description":"globalize-compiler is a build tool that statically extracts Global.js formatters and parsers from source code and compiles them into a standalone JavaScript bundle. Version 1.1.1 is the current stable release with no recent updates. It is used alongside Globalize v1.5.0+ and CLDR data (>=25). Key differentiators: (1) eliminates runtime message/CLDR data dependencies for performance, (2) provides both CLI and programmatic API (compile, extract, compileExtracts), (3) supports custom templates for output. Primarily for Node.js build pipelines; not meant for direct browser use.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/globalizejs/globalize-compiler","tags":["javascript","globalize"],"install":[{"cmd":"npm install globalize-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add globalize-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add globalize-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for CLDR locale data","package":"cldr-data","optional":false},{"reason":"Peer dependency for Globalize runtime","package":"globalize","optional":false},{"reason":"Peer dependency for timezone data","package":"iana-tz-data","optional":false}],"imports":[{"note":"ESM import works in Node 12+. CommonJS `require` is also valid but named import preferred for clarity.","wrong":"const compile = require('globalize-compiler').compile","symbol":"compile","correct":"import { compile } from 'globalize-compiler'"},{"note":"extract is a top-level export, not a subpath. CommonJS `require('globalize-compiler')` returns the module object.","wrong":"const extract = require('globalize-compiler/extract')","symbol":"extract","correct":"import { extract } from 'globalize-compiler'"},{"note":"compileExtracts is a top-level export; incorrect subpath will cause module not found.","wrong":"const { compileExtracts } = require('globalize-compiler/lib/compileExtracts')","symbol":"compileExtracts","correct":"import { compileExtracts } from 'globalize-compiler'"}],"quickstart":{"code":"import { compile, extract } from 'globalize-compiler';\nimport Globalize from 'globalize';\n\n// Extract formatters from a source file\nconst extractFn = extract('path/to/your/source.js');\n\n// Create Globalize instance with locale data\n// (In real usage you'd load CLDR data)\nconst globalize = new Globalize('en');\n\n// Get formatters/parsers by calling extract function\nconst formattersAndParsers = extractFn(globalize);\n\n// Compile them into a bundle string\nconst bundle = compile(formattersAndParsers, { template: null });\n\nconsole.log(bundle); // Output JavaScript bundle","lang":"typescript","description":"Shows how to extract formatters from a source file and compile them into a JavaScript bundle using globalize-compiler."},"warnings":[{"fix":"Run `npm install cldr-data globalize iana-tz-data --save-dev`.","message":"Requires peer dependencies cldr-data, globalize, and iana-tz-data to be installed. Missing peer deps cause runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure formatter/parser creation calls use literal method names (e.g. `Globalize.formatNumber` not `Globalize['format'+'Number']`).","message":"The `extract` function only recognizes static calls to Globalize methods; dynamic or computed method names will not be extracted.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Update code to pass formatters/parsers as an array or object; see migration guide.","message":"Version 1.0.0 changed the API: `compile` now expects an array or object of formatters/parsers instead of the previous argument structure.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use the programmatic API to pass CLDR data directly.","message":"The `--cldr` CLI flag is deprecated in favor of loading CLDR data via the API or separate data files.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Combine CLDR data into a single JSON file before passing to CLI.","message":"CLI does not support loading CLDR data from multiple files; only one file via `-c` flag.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install globalize-compiler --save-dev`.","cause":"Package not installed in node_modules.","error":"Error: Cannot find module 'globalize-compiler'"},{"fix":"Use `const globalizeCompiler = require('globalize-compiler');` then `globalizeCompiler.compile(...)` or `const { compile } = require('globalize-compiler');`.","cause":"CommonJS require returns an object with methods; destructure incorrectly.","error":"TypeError: globalizeCompiler.compile is not a function"},{"fix":"Ensure you load CLDR data via `-c` flag or provide it in the API call.","cause":"Missing CLDR data when using compiled bundle.","error":"Error: No CLDR data provided for locale en"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}