Registry / serialization / rollup-plugin-formatjs

rollup-plugin-formatjs

JSON →
library3.0.0jsnpmunverified

A Rollup and Vite plugin that applies formatjs (react-intl) message extraction and translation transforms during the build process. Version 3.0.0 is the latest stable release, with monthly updates. It seamlessly integrates with the formatjs ecosystem, supporting both Rollup (^3) and Vite via plugin-compat. Unlike manual extraction, this automates the pipeline from source code to compiled messages, reducing configuration overhead. Ships TypeScript definitions.

npm install rollup-plugin-formatjs
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-FORM
R
rollup-plugin-formatjs
serializationjavascriptv3.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatjs
✓ import formatjs from 'rollup-plugin-formatjs'
✗ import { formatjs } from 'rollup-plugin-formatjs'
Default export; named import breaks in v3+.
formatjs
✓ const formatjs = require('rollup-plugin-formatjs')
✗ const { formatjs } = require('rollup-plugin-formatjs')
CommonJS default import; destructuring fails.
FormatjsOptions
✓ import type { FormatjsOptions } from 'rollup-plugin-formatjs'
TypeScript type import for configuration object.

Basic Rollup config that applies formatjs transforms to source files, generating compiled message IDs and optimizations.

import formatjs from 'rollup-plugin-formatjs'; import { defineConfig } from 'rollup'; export default defineConfig({ input: 'src/index.js', plugins: [ formatjs({ idInterpolationPattern: '[sha512:contenthash:base64:6]', ast: true, extractFromFormatMessageCall: true, additionalFunctionNames: [], additionalComponentNames: [], removeDefaultMessage: false, overrideIdFn: undefined, sourceMaps: false, include: '**/*.{js,ts,jsx,tsx}', exclude: 'node_modules/**' }) ], output: { file: 'dist/bundle.js', format: 'es' } });
Debug
Known issues
breakingv3 dropped support for Rollup <3.0.0.
fix
Upgrade Rollup to ^3.0.0.
affects: <3.0.0
gotchaDefault export must be imported directly; named destructuring fails silently with undefined or error.
fix
Use default import: import formatjs from 'rollup-plugin-formatjs'
affects: >=3.0.0
gotchaOption 'extractFromFormatMessageCall' defaults to false; without it, message extraction does not cover formatMessage calls, only <FormattedMessage> components.
fix
Set extractFromFormatMessageCall: true in plugin options.
affects: >=3.0.0
gotchaPlugin may fail silently if source code contains invalid ICU messages; no runtime error is thrown.
fix
Validate messages with @formatjs/cli extract command before building.
affects: >=3.0.0
gotchaTypeScript type 'FormatjsOptions' is exported but not listed in package.json exports field; some bundlers may not resolve it.
fix
Use @ts-ignore or import via explicit path to types: import type { FormatjsOptions } from 'rollup-plugin-formatjs/lib/types'
affects: >=3.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/rollup-plugin-formatjs/dist/index.js from /path/to/project/rollup.config.js not supported.
Using CommonJS require() with package set to type: module or ESM-only dist.
fix
Switch to ESM imports (import formatjs from 'rollup-plugin-formatjs') or rename config to .mjs.
TypeError: (0 , _rollupPluginFormatjs.default) is not a function
Named import instead of default import.
fix
Use import formatjs from 'rollup-plugin-formatjs' instead of import { formatjs } from 'rollup-plugin-formatjs'.
Error: Cannot find module '@formatjs/icu-messageformat-parser'
Transitive dependency not installed (e.g., using npm 6 with no dedupe).
fix
Run npm install or explicitly add @formatjs/icu-messageformat-parser to your dependencies.
Error: [object Object] is not a PostCSS plugin (or similar message when used with other tools)
Incorrect plugin ordering; formatjs plugin placed before CSS-related plugins in Rollup array.
fix
Ensure formatjs plugin comes after CSS plugins or is configured only for JS files with include/exclude.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
rolluprequiredRequired as peer dependency for Rollup plugin interface.
@formatjs/icu-messageformat-parserrequiredUsed internally for parsing ICU messages; installed automatically as a transitive dependency.
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-formatjs — npm install rollup-plugin-formatjs · libregistry