messageformat-cli

raw JSON →
2.1.1 verified Sat Apr 25 auth: no javascript maintenance

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.

error Error: Cannot find module 'messageformat'
cause Peer dependency 'messageformat' not installed.
fix
npm install messageformat@2
error messageformat-cli: command not found
cause CLI not installed globally or not in PATH.
fix
npm install -g messageformat-cli messageformat@2
error SyntaxError: Unexpected token 'export'
cause Attempted to import the output file using ESM syntax, but output is CommonJS.
fix
Use require() instead of import.
deprecated messageformat-cli is deprecated; use messageformat 4.x CLI instead.
fix Migrate to messageformat 4.x and its built-in CLI.
breaking messageformat 2.x is a peer dependency; v3+ has breaking changes.
fix Install messageformat@2 as a peer dependency.
gotcha Output modules are CommonJS, not ESM. Cannot be imported with import syntax without a bundler.
fix Use require() or configure bundler to handle CommonJS.
npm install messageformat-cli
yarn add messageformat-cli
pnpm add messageformat-cli

Shows installation, creating a message JSON file, running the CLI to compile, and using the generated module.

npm install -g messageformat-cli messageformat@2
# Create a JSON file with translations
cat > messages.json <<EOF
{
  "greeting": "Hello {name}!",
  "farewell": "Goodbye {name}!"
}
EOF
# Compile to JavaScript
messageformat-cli messages.json messages.js
# Use in Node.js
const greeting = require('./messages.js').greeting;
console.log(greeting({ name: 'World' })); // Output: Hello World!