#7519·formatjs

@formatjs/intl: intl-messageformat is still a static import — the parser stays in the bundle even for precompiled messages

Author: goranpopoCreated Sep 28, 2026Updated Sep 29, 2026

Which package is this for?

@formatjs/intl 2.3.1 (via react-intl 12)

Describe the problem

#1945 made the parser injectable (IntlMessageFormat.__parse), which is great for apps that precompile their messages — but intl-messageformat itself is still a static import in @formatjs/intl's core modules:

  • lib/src/message.js: import { IntlMessageFormat } from 'intl-messageformat'
  • lib/src/displayName.js / lib/src/list.js: import { FormatError, ErrorCode } from 'intl-messageformat'

So even an app that hands every message to the intl layer as a precompiled AST (or never formats a dynamic string) still ships the full parser chain. Measured in a Next 16 + Turbopack production build: @formatjs/icu-messageformat-parser at 8.5 kB gz plus the intl-messageformat core, ~18-20 kB gz on every route of a 47-route app, for a code path our messages never take.

Suggestion

Split the error codes/type guards out of intl-messageformat (they are constants, not parsing), and either make the IntlMessageFormat construction lazy (await import on first dynamic-string format, with a clear throw if a raw string arrives without the parser loaded — the #1400 failure mode made explicit) or move the parser behind a peer entrypoint that precompiling apps can skip.

Motivation

For apps that precompile, the parser is dead weight on every page. The #1945 contract ("the parser is optional") is only half-shipped: injection is optional, the import is not.