Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Description strangely missing using babel 6 #26

Closed
emmenko opened this issue Dec 19, 2015 · 1 comment
Closed

Description strangely missing using babel 6 #26

emmenko opened this issue Dec 19, 2015 · 1 comment

Comments

@emmenko
Copy link

emmenko commented Dec 19, 2015

I'm in the process of upgrading to babel 6 and noticed this plugin throws an error because of missing description field (with enforceDescriptions: true).

All my messages have the description field, so this is not the problem (also it was working with babel 5).

For example, given this message

const messages = defineMessages({
  builtWith: {
    id: 'footer.builtWith',
    description: 'Mention how the site is built with',
    defaultMessage: 'This site is built with <3 using {link}'
  }
})

I get the following error

SyntaxError: lib/components/Footer.js: [React Intl] Message must have a `description`.
  2 | import { defineMessages, FormattedMessage } from 'react-intl'
  3 |
> 4 | const messages = defineMessages({
    |                  ^
  5 |   builtWith: {
  6 |     id: 'footer.builtWith',
  7 |     description: 'Mention how the site is built with',

If I log the descriptor argument and state.opts of the storeMessage function I see that it's called multiple times

{ id: 'footer.builtWith',
  description: 'Mention how the site is built with',
  defaultMessage: 'This site is built with <3 using {link}' } {}
{ id: 'footer.builtWith',
  defaultMessage: 'This site is built with <3 using {link}' } { messagesDir: './_translations', enforceDescriptions: true }

As you can see there are 2 differences here:

  • the first time description is present, but state.opts is empty
  • the second time description is somehow missing (thus throwing the error) and state.opts is the options defined for the plugin in .babelrc

PS: my .babelrc

{
  "presets": [ "es2015", "react", "stage-0" ],
  "plugins": [
    [ "react-intl", {
      "messagesDir": "./_translations",
      "enforceDescriptions": true
    }]
  ]
}

Any idea what's going on here? Thanks

@ericf
Copy link
Collaborator

ericf commented Dec 22, 2015

You're likely running the plugin multiple times. See: #25 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants