Registry / serialization / react-intl.macro

react-intl.macro

JSON →
library0.3.7jsnpmunverified

Run react-intl at build-time with babel-plugin-macros. Current stable version is 0.3.7 (last released Feb 2020; no recent updates, likely maintenance mode). It extracts react-intl defineMessages, FormattedMessage, and FormattedHTMLMessage calls into JSON files during build, leveraging babel-plugin-macros without needing a separate Babel plugin. Different from babel-plugin-react-intl (requires explicit Babel config) and react-intl-cra (Create React App specific) – this macro approach works with any macro-enabled setup (CRA, Next.js, custom builds). Requires react-intl@2 and babel-plugin-macros.

npm install react-intl.macro
INSTALL
IMPORT
SIG · REACT-INTL.MACRO
R
react-intl.macro
serializationjavascriptv0.3.7
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–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

defineMessages
✓ import { defineMessages } from 'react-intl.macro'
✗ import { defineMessages } from 'react-intl'
Replace react-intl import with react-intl.macro to enable build-time extraction
FormattedMessage
✓ import { FormattedMessage } from 'react-intl.macro'
✗ import { FormattedMessage } from 'react-intl'
FormattedMessage from the macro extracts defaultMessage during build
FormattedHTMLMessage
✓ import { FormattedHTMLMessage } from 'react-intl.macro'
✗ import { FormattedHTMLMessage } from 'react-intl'
FormattedHTMLMessage is also provided by the macro for extraction

Shows installation, config, and usage of react-intl.macro to replace react-intl imports and extract messages during build.

// Install dependencies // yarn add react-intl.macro react-intl babel-plugin-macros // babel-plugin-macros.config.js module.exports = { 'react-intl': { verbose: false, }, }; // Component.js import { defineMessages, FormattedMessage } from 'react-intl.macro'; const messages = defineMessages({ 'App.greet': { id: 'App.greet', defaultMessage: 'Hello, {name}!', description: 'Greeting to welcome the user', }, }); const App = () => ( <FormattedMessage id="App.welcome" defaultMessage="Welcome to our app" description="Welcome message" /> ); // Build with MESSAGE_DIR environment variable // MESSAGE_DIR='./.messages' react-scripts build // Output: .messages/App.json containing extracted messages
Debug
Known issues
gotchaRequires react-intl@2; not compatible with react-intl v3+ (which uses createIntl and Provider changes).
fix
Use react-intl v2.x or consider alternative extraction tools for modern react-intl.
affects: >=0.0.0
gotchaMESSAGE_DIR environment variable must be set during build; otherwise no output is produced.
fix
Set MESSAGE_DIR to a directory path, e.g., MESSAGE_DIR='./.messages' react-scripts build
affects: >=0.0.0
deprecatedPackage last updated in 2020; no longer maintained. May not work with newer Babel or macro versions.
fix
Consider using babel-plugin-react-intl (v9+) or @formatjs/cli for extraction in modern projects.
affects: >=0.0.0
gotchaOnly extracts defineMessages, FormattedMessage, and FormattedHTMLMessage. Other react-intl components (e.g., injectIntl) are not extracted and must still be imported from 'react-intl'.
fix
Keep injectIntl and other non-extracted imports from 'react-intl'; only replace extraction-targets with react-intl.macro.
affects: >=0.0.0
Errors
Common errors & fixes
Module not found: Can't resolve 'react-intl.macro'
Missing installation or babel-plugin-macros not configured.
fix
Install react-intl.macro and babel-plugin-macros; ensure Babel config includes 'macros' plugin.
Error: [BABEL] ...: Cannot find module 'babel-plugin-macros'
babel-plugin-macros is not installed or not in the Babel plugins list.
fix
Run 'yarn add babel-plugin-macros' and add 'macros' to your Babel plugins in babel.config.js.
No message output files generated after build
MESSAGE_DIR environment variable not set or macro not correctly replacing imports.
fix
Set MESSAGE_DIR environment variable (e.g., MESSAGE_DIR='./.messages') and ensure imports come from 'react-intl.macro', not 'react-intl'.
Upgrade
Version history
0.3.7latest on npm
Audit
Dependencies
react-intlrequiredPeer dependency; the macro replaces imports from react-intl but react-intl is still required for runtime
babel-plugin-macrosrequiredRequired for macro to work; must be installed and configured in Babel config
Agent activity
4 hits · last 30 days
node
4
Resources
react-intl.macro — npm install react-intl.macro · libregistry