evenchange4 / react-intl.macro

Extract react-intl messages with babel-plugin-macros.
MIT License
37 stars 6 forks source link

Cannot use defineMessages on an object reference #90

Open MattKunze opened 5 years ago

MattKunze commented 5 years ago

I think this might be similar to #81, but I'm getting compiler errors instead of undefined keys.

Passing a predefined object reference to defineMessages fails, I'm guessing the code isn't following the reference in the Babel AST and instead assuming an object is directly defined:

import { defineMessages } from "react-intl.macro"
const messages = {
  key: { id: "key", defaultMessage: "Default Message" }
}
defineMessages(messages)

this fails with:

TypeError: react-intl.macro: properties.map is not a function Learn more: https://www.npmjs.com/package/react-intl.macro
    at Array.map (<anonymous>)

My use case is I have a shared library where the messages are defined, but the build process isn't working correctly for the sub module (different issues with Rollup). So I'm trying to import the messages in my app and forward them to defineMessages so they get picked up when I build the available translations.

langpavel commented 4 years ago

This is unfortunately not possible. Macros are limited, they can hardly follow reference in same file. With import this is really mission impossible.