@intlify/message-compiler review
@intlify/message-compiler 11.4.10 is the parser and code generator used for Vue I18n message strings. It understands named and numbered placeholders, pipe plurals, linked keys, modifiers, and literal interpolation. baseCompile() returns JavaScript function source plus an AST, while createParser() exposes the AST step by itself. Neither API selects a locale or formats the final message for an application. The current stable release was published with a core-base devtools fix and lists no compiler-specific change; Intlify versions these monorepo packages together.
@intlify/message-compiler 11.4.8 installed in 2.4 seconds, occupied 1 MB across three packages, and produced a 5.9 KB gzipped browser bundle in our sandbox, making the low-level compiler cheap enough for Vue I18n tooling. Application teams should use vue-i18n or its unplugin because this API returns code or AST data and leaves the runtime helper contract to the caller.
We installed it
| Install | ✓ · 2.4s | 3 packages on disk · 1 MB |
| Import | ✓ | ESM import works · require() works · CommonJS package with exports map |
| Browser | 5.9 KB | gzipped (18.1 KB minified), bundled with esbuild |
| Types | ✓ | TypeScript types bundled |
| Known vulns | 0 | 0 critical · 0 high · 0 moderate · 0 low (npm audit) |
Answers from our run
Does @intlify/message-compiler install cleanly?
Yes. In a fresh container with an empty cache, npm install @intlify/message-compiler finished in 2 seconds, leaving 3 packages and 1 MB on disk. npm audit reported no known vulnerabilities.
How much does @intlify/message-compiler add to a browser bundle?
5.9 KB gzipped (18.1 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.
Does @intlify/message-compiler work with both ESM and CommonJS?
Yes. Both import '@intlify/message-compiler' and require('@intlify/message-compiler') worked in Node 22 in our run. The package is published as CommonJS with an exports map.
Does @intlify/message-compiler include TypeScript types?
Yes, type declarations ship inside the package, so no @types install is needed.
@intlify/message-compiler or @intlify/unplugin-vue-i18n: which should you use?
@intlify/unplugin-vue-i18n: Use it for Vue application builds that should precompile locale files through supported Vite or webpack integration. @intlify/message-compiler 11.4.8 installed in 2.4 seconds, occupied 1 MB across three packages, and produced a 5.9 KB gzipped browser bundle in our sandbox, making the low-level compiler cheap enough for Vue I18n tooling.
When should you not use @intlify/message-compiler?
Your Vue app only needs translations at runtime; vue-i18n and its official unplugin own locale fallback, formatting, and build integration
Use it if
- You are building a Vue I18n linter, editor, extractor, or precompiler that must accept the project's exact message grammar
- Build-time tooling needs generated message-function source and optional Node-side source maps
- Your compatible Intlify runtime consumes optimized JIT ASTs instead of dynamically generated functions
- Syntax diagnostics need numeric error codes plus offsets, lines, columns, and compiler domains
- Your Vue app only needs translations at runtime; vue-i18n and its official unplugin own locale fallback, formatting, and build integration
- CI or production still uses Node 20; every stable release from 11.4.3 onward declares Node 22 as the minimum
- Your catalogs use ICU MessageFormat; pipe plurals and linked keys are Vue I18n syntax and will not interchange with FormatJS catalogs
- Messages can come from untrusted users; evaluating baseCompile output with new Function turns message text into executable code and can violate a strict CSP
- You need a well-documented standalone compiler contract; the package README is one sentence and the generated function relies on Intlify-specific context helpers
Setup reality
Our clean install used @intlify/message-compiler 11.4.8 and completed in 2.4 seconds. It put three packages and 1 MB on disk. The package declared two direct dependencies, no peers, 440 KB unpacked, bundled TypeScript declarations, and an MIT license. npm audit found 0 known vulnerabilities. The registry now marks 11.4.10 as stable, so those measurements describe 11.4.8 rather than the two later lockstep releases.
No account, key, or configuration file is needed. Node 22 is required. Keep @intlify/message-compiler aligned with the rest of an Intlify stack because it pins @intlify/shared to the exact package version. baseCompile() emits source for a function that expects helpers such as normalize, interpolate, named, list, plural, and linked from an Intlify runtime context. Calling the generated function with an ordinary data object is insufficient.
The measured 11.4.8 package used CommonJS packaging with an exports map, and require() plus ESM import both worked in our sandbox. Its browser bundle measured 18.1 KB minified and 5.9 KB gzipped with an import-all esbuild entry. JIT mode returns an empty code string and an AST for a compatible runtime. Setting minify changes that AST's property representation, which can break home-grown consumers that expect descriptive keys.
Compilation is synchronous. By default, a syntax error throws with a numeric code and source location. Supplying onError collects the error and lets compilation continue, so discard the returned code and AST whenever the callback ran. Source maps need sourceMap: true, location data, a meaningful filename, and the Node build. Evaluate generated code only from trusted catalogs; application builds are safer when the official unplugin compiles messages ahead of time.
Patterns
Compile a named placeholder compile-named-message
import {baseCompile} from '@intlify/message-compiler';
const compiled = baseCompile('Hello, {name}!');
console.log(compiled.code);baseCompile returns function source and an AST. The emitted function expects Intlify's named, interpolate, and normalize helpers.
Emit an arrow function generate-arrow-source
const {code} = baseCompile('Welcome, {name}', {
mode: 'arrow',
needIndent: false,
breakLineCode: ';'
});Arrow mode changes the generated source form. It does not replace the ctx argument or any runtime helpers.
Compile pipe-separated plural cases compile-plurals
const {code} = baseCompile(
'no files | one file | {count} files'
);The three cases use Vue I18n plural grammar. An Intlify plural helper chooses a case when the function runs.
Compile numbered values compile-list-placeholders
const result = baseCompile('Hello, {0}. Queue position: {1}.');
console.log(result.ast);A numeric placeholder becomes a call to the list helper, while a name such as {count} uses the named helper.
Compile a linked locale key compile-linked-key
const simple = baseCompile('Read @:legal.terms');
const modified = baseCompile('Email @.lower:labels.support');Compilation records the link and modifier. The runtime resolves the locale key and supplies the lower modifier.
Insert a literal at-sign or pipe escape-special-character
const email = baseCompile("Write to {'@'}example.test");
const separator = baseCompile("Use {'|'} as the separator");Single-quoted literal interpolation prevents @ from starting a linked message and | from splitting plural cases.
Create an AST without code generation parse-message
import {createParser} from '@intlify/message-compiler';
const parser = createParser();
const ast = parser.parse('Hello, {name}!');
console.log(ast.body);createParser returns Vue I18n compiler nodes with location data enabled unless location is set to false.
Collect syntax diagnostics collect-errors
const diagnostics = [];
const result = baseCompile('Hello, {', {
onError(error) {
diagnostics.push({code: error.code, domain: error.domain, location: error.location});
}
});
if (diagnostics.length > 0) throw new Error(JSON.stringify(diagnostics));Providing onError replaces the default throw. Treat any callback invocation as a failed catalog entry even if result exists.
Omit AST source ranges remove-locations
const {ast} = baseCompile('Hello, {name}!', {
jit: true,
location: false
});Disabling locations removes line, column, offset, and source slices that editors and precise diagnostics rely on.
Build an optimized runtime AST create-jit-ast
const result = baseCompile('Hello, {name}!', {
jit: true,
optimize: true
});
console.assert(result.code === '');JIT mode deliberately leaves code empty. A matching Intlify runtime interprets the returned AST.
Compact a JIT message tree minify-jit-ast
const {ast} = baseCompile('Hello, {name}!', {
jit: true,
optimize: true,
minify: true
});Minification rewrites descriptive node properties. Custom AST readers must support Intlify's compact representation before enabling it.
Attach a source map generate-source-map
const result = baseCompile('Hello, {name}!', {
filename: 'locales/en.json',
sourceMap: true,
location: true
});
console.log(result.map);Source-map output needs the Node build and location tracking. Use the catalog path as filename so mappings identify the source asset.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| @intlify/unplugin-vue-i18n | npm | Use it for Vue application builds that should precompile locale files through supported Vite or webpack integration |
| @messageformat/core | npm | Use it when an application needs to compile ICU-style MessageFormat rather than Vue I18n grammar |
| @formatjs/icu-messageformat-parser | npm | Use it when tooling needs the FormatJS ICU AST for extraction, validation, or editor features |
| intl-messageformat | npm | Use it when runtime code must parse and format ICU messages with plural, select, date, and number rules |
More cli & tooling guides
chalk · commander · typescript · esbuild · yargs · click · the whole shelf →
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.

