{"id":18546,"library":"messageformat-cli","title":"messageformat-cli","description":"CLI for compiling ICU MessageFormat strings using the messageformat library. Version 2.1.1 is current stable. Provides a command-line interface to convert messageformat JSON files to JavaScript modules. Requires messageformat as a peer dependency. Lightweight wrapper with no additional runtime dependencies. Supports Node.js >=6.0. Not actively developed; core library has moved to version 4.x with breaking changes.","status":"maintenance","version":"2.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/messageformat/messageformat","tags":["javascript","i18n","icu","messageformat","internationalization"],"install":[{"cmd":"npm install messageformat-cli","lang":"bash","label":"npm"},{"cmd":"yarn add messageformat-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add messageformat-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for compilation","package":"messageformat","optional":false}],"imports":[{"note":"No JavaScript import available; use command line only.","symbol":"main","correct":"messageformat-cli is used as a CLI tool; no programmatic import. Run via npx messageformat-cli or global install."},{"note":"Output files use module.exports, so require() is required.","wrong":"import msg from './messages.js'; // Output is CommonJS, not ESM","symbol":"compile output","correct":"messageformat-cli generates a .js file that can be imported as a CommonJS module. const msg = require('./messages.js');"},{"note":"Direct CLI invocation, not via npm scripts.","wrong":"npm run messageformat-cli input.json output.js","symbol":"CLI usage","correct":"npx messageformat-cli input.json output.js"}],"quickstart":{"code":"npm install -g messageformat-cli messageformat@2\n# Create a JSON file with translations\ncat > messages.json <<EOF\n{\n  \"greeting\": \"Hello {name}!\",\n  \"farewell\": \"Goodbye {name}!\"\n}\nEOF\n# Compile to JavaScript\nmessageformat-cli messages.json messages.js\n# Use in Node.js\nconst greeting = require('./messages.js').greeting;\nconsole.log(greeting({ name: 'World' })); // Output: Hello World!","lang":"typescript","description":"Shows installation, creating a message JSON file, running the CLI to compile, and using the generated module."},"warnings":[{"fix":"Migrate to messageformat 4.x and its built-in CLI.","message":"messageformat-cli is deprecated; use messageformat 4.x CLI instead.","severity":"deprecated","affected_versions":">=2.0"},{"fix":"Install messageformat@2 as a peer dependency.","message":"messageformat 2.x is a peer dependency; v3+ has breaking changes.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Use require() or configure bundler to handle CommonJS.","message":"Output modules are CommonJS, not ESM. Cannot be imported with import syntax without a bundler.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install messageformat@2","cause":"Peer dependency 'messageformat' not installed.","error":"Error: Cannot find module 'messageformat'"},{"fix":"npm install -g messageformat-cli messageformat@2","cause":"CLI not installed globally or not in PATH.","error":"messageformat-cli: command not found"},{"fix":"Use require() instead of import.","cause":"Attempted to import the output file using ESM syntax, but output is CommonJS.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}