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.
Common errors
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.
Warnings
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.
Install
npm install messageformat-cli yarn add messageformat-cli pnpm add messageformat-cli Imports
- main
messageformat-cli is used as a CLI tool; no programmatic import. Run via npx messageformat-cli or global install. - compile output wrong
import msg from './messages.js'; // Output is CommonJS, not ESMcorrectmessageformat-cli generates a .js file that can be imported as a CommonJS module. const msg = require('./messages.js'); - CLI usage wrong
npm run messageformat-cli input.json output.jscorrectnpx messageformat-cli input.json output.js
Quickstart
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!