{"id":22033,"library":"rollup-plugin-formatjs","title":"rollup-plugin-formatjs","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/hummingbird-me/rollup-plugin-formatjs","tags":["javascript","rollup","plugin","formatjs","rollup-plugin","vite-plugin","typescript"],"install":[{"cmd":"npm install rollup-plugin-formatjs","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-formatjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-formatjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as peer dependency for Rollup plugin interface.","package":"rollup","optional":false},{"reason":"Used internally for parsing ICU messages; installed automatically as a transitive dependency.","package":"@formatjs/icu-messageformat-parser","optional":false}],"imports":[{"note":"Default export; named import breaks in v3+.","wrong":"import { formatjs } from 'rollup-plugin-formatjs'","symbol":"formatjs","correct":"import formatjs from 'rollup-plugin-formatjs'"},{"note":"CommonJS default import; destructuring fails.","wrong":"const { formatjs } = require('rollup-plugin-formatjs')","symbol":"formatjs","correct":"const formatjs = require('rollup-plugin-formatjs')"},{"note":"TypeScript type import for configuration object.","wrong":null,"symbol":"FormatjsOptions","correct":"import type { FormatjsOptions } from 'rollup-plugin-formatjs'"}],"quickstart":{"code":"import formatjs from 'rollup-plugin-formatjs';\nimport { defineConfig } from 'rollup';\n\nexport default defineConfig({\n  input: 'src/index.js',\n  plugins: [\n    formatjs({\n      idInterpolationPattern: '[sha512:contenthash:base64:6]',\n      ast: true,\n      extractFromFormatMessageCall: true,\n      additionalFunctionNames: [],\n      additionalComponentNames: [],\n      removeDefaultMessage: false,\n      overrideIdFn: undefined,\n      sourceMaps: false,\n      include: '**/*.{js,ts,jsx,tsx}',\n      exclude: 'node_modules/**'\n    })\n  ],\n  output: { file: 'dist/bundle.js', format: 'es' }\n});","lang":"typescript","description":"Basic Rollup config that applies formatjs transforms to source files, generating compiled message IDs and optimizations."},"warnings":[{"fix":"Upgrade Rollup to ^3.0.0.","message":"v3 dropped support for Rollup <3.0.0.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Use default import: import formatjs from 'rollup-plugin-formatjs'","message":"Default export must be imported directly; named destructuring fails silently with undefined or error.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Set extractFromFormatMessageCall: true in plugin options.","message":"Option 'extractFromFormatMessageCall' defaults to false; without it, message extraction does not cover formatMessage calls, only <FormattedMessage> components.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Validate messages with @formatjs/cli extract command before building.","message":"Plugin may fail silently if source code contains invalid ICU messages; no runtime error is thrown.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use @ts-ignore or import via explicit path to types: import type { FormatjsOptions } from 'rollup-plugin-formatjs/lib/types'","message":"TypeScript type 'FormatjsOptions' is exported but not listed in package.json exports field; some bundlers may not resolve it.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Switch to ESM imports (import formatjs from 'rollup-plugin-formatjs') or rename config to .mjs.","cause":"Using CommonJS require() with package set to type: module or ESM-only dist.","error":"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."},{"fix":"Use import formatjs from 'rollup-plugin-formatjs' instead of import { formatjs } from 'rollup-plugin-formatjs'.","cause":"Named import instead of default import.","error":"TypeError: (0 , _rollupPluginFormatjs.default) is not a function"},{"fix":"Run npm install or explicitly add @formatjs/icu-messageformat-parser to your dependencies.","cause":"Transitive dependency not installed (e.g., using npm 6 with no dedupe).","error":"Error: Cannot find module '@formatjs/icu-messageformat-parser'"},{"fix":"Ensure formatjs plugin comes after CSS plugins or is configured only for JS files with include/exclude.","cause":"Incorrect plugin ordering; formatjs plugin placed before CSS-related plugins in Rollup array.","error":"Error: [object Object] is not a PostCSS plugin (or similar message when used with other tools)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}