{"id":20205,"library":"messageformat-loader","title":"messageformat-loader","description":"Webpack loader that compiles MessageFormat ICU message strings into JavaScript modules at build time. Supports JSON, YAML, and JS source files containing ICU MessageFormat strings. Compatible with messageformat 1.x and 2.x. The loader transforms message resources into pre-compiled functions for efficient runtime internationalization. While the core messageformat library has moved to v4 (prerelease) with a rewritten API and MF2 spec support, this loader remains at v0.8.1 and only supports the older 1.x/2.x versions. Key differentiator: integrates MessageFormat compilation into webpack pipeline, avoiding runtime compilation overhead.","status":"maintenance","version":"0.8.1","language":"javascript","source_language":"en","source_url":"https://github.com/messageformat/messageformat","tags":["javascript","i18n","pluralformat","icu","selectformat","messageformat","internationalization","json","yaml"],"install":[{"cmd":"npm install messageformat-loader","lang":"bash","label":"npm"},{"cmd":"yarn add messageformat-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add messageformat-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency; must be installed separately as messageformat 1.x or 2.x","package":"messageformat","optional":false}],"imports":[{"note":"Loader is used in webpack config, not in application code. Configure with 'messageformat-loader' as the loader name.","wrong":"loader: 'messageformat-loader' // string is fine; but if using options object, must specify properly","symbol":"default export","correct":"// In webpack.config.js:\nmodule.exports = {\n  module: {\n    rules: [\n      { test: /\\.json$/, use: 'messageformat-loader' }\n    ]\n  }\n}"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  entry: './src/index.js',\n  module: {\n    rules: [\n      {\n        test: /\\.json$/,  // or .yaml, .yml\n        use: [\n          {\n            loader: 'messageformat-loader',\n            options: {\n              locale: 'en',         // default locale\n              locales: ['en', 'fr'], // available locales\n              biDiSupport: false\n            }\n          }\n        ]\n      }\n    ]\n  }\n};\n\n// src/messages/en.json\n{\n  \"greeting\": \"Hello {name}!\",\n  \"items\": \"You have {count, plural, =0 {no items} one {# item} other {# items}}.\"\n}\n\n// src/index.js\nimport messages from './messages/en.json';\nconsole.log(messages.greeting({ name: 'World' })); // \"Hello World!\"\nconsole.log(messages.items({ count: 3 })); // \"You have 3 items.\"","lang":"javascript","description":"Configures webpack to load JSON message files and compile ICU patterns using messageformat-loader."},"warnings":[{"fix":"Use messageformat 2.x (e.g., 'messageformat': '^2.0.0') or stay on 1.x. Do not install messageformat@4.","message":"Loader only supports messageformat 1.x or 2.x; does not work with messageformat v4","severity":"gotcha","affected_versions":">=0.8.0"},{"fix":"Consider migrating to messageformat v4 and using a custom loader or runtime compilation with @messageformat/core","message":"The loader is no longer actively maintained; the underlying messageformat library has moved to v4 with a completely different API","severity":"deprecated","affected_versions":">=0.8.0"},{"fix":"Always specify the 'locale' or 'locales' option matching your message files","message":"Locale option is required; if not provided, the loader falls back to 'en' but may produce incorrect date/number formatting for other locales","severity":"gotcha","affected_versions":">=0.8.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.0.0","cause":"Missing peer dependency messageformat","error":"Module not found: Error: Can't resolve 'messageformat' in '...'"},{"fix":"npm install messageformat@^2.0.0","cause":"messageformat version not compatible (e.g., v4 installed)","error":"Error: Cannot find module 'messageformat/compile-module'"},{"fix":"Configure as `loader: 'messageformat-loader'` inside a `rules` array, not as a plugin.","cause":"Using loader incorrectly in webpack config (e.g., as a plugin)","error":"TypeError: messageformat_loader is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}