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

Description strangely missing using babel 6 #26

Closed
@emmenko

Description

@emmenko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions