Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an error for using FormattedHTMLMessage #79

Open
udayrajMT opened this issue Jul 1, 2020 · 1 comment
Open

Getting an error for using FormattedHTMLMessage #79

udayrajMT opened this issue Jul 1, 2020 · 1 comment

Comments

@udayrajMT
Copy link

udayrajMT commented Jul 1, 2020

  • version:
  • node version: 12
  • yarn version: 1.22
  • react-intl version: 2.9.0

Do you want to request a feature or report a bug?:
bug.
(would be a feature if this functionality is missing altogether)

What is the current behavior?:
When using FormattedHTMLMessage to parse the following string -
Sample message string : Hello <span class='bold'>'{name}'</span>

I'm getting an 'unexpected token' error.

yarn run v1.22.4
$ extract-messages -l=messages -o dist -d en './src/components/**/!(*.test).js'
SyntaxError: [React Intl] Message failed to parse. See: https://formatjs.io/docs/icu-syntax
SyntaxError: Expected "#", "'", "\n", "{", argumentElement, double apostrophes, end of input, or tagElement but "<" found. (This is an error on an internal node. Probably an internal error.)
    at File.buildCodeFrameError (/project/node_modules/@babel/core/lib/transformation/file/file.js:248:12)
    at NodePath.buildCodeFrameError (/project/node_modules/@babel/traverse/lib/path/index.js:144:21)
    at getICUMessageValue (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:66:27)
    at evaluateMessageDescriptor (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:113:26)
    at processMessageObject (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:388:38)
    at Array.forEach (<anonymous>)
    at PluginPass.CallExpression (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:415:38)
    at newFn (/project/node_modules/@babel/traverse/lib/visitors.js:179:21)
    at NodePath._call (/project/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (/project/node_modules/@babel/traverse/lib/path/context.js:42:17)
error Command failed with exit code 1.

What is the expected behavior?:
Expecting this to be extracted like the other messages.

Suggested solution:

@udayrajMT udayrajMT changed the title Getting an error for using html inside message strings Getting an error for using FormattedHTMLMessage Jul 2, 2020
@TriPSs
Copy link

TriPSs commented Mar 30, 2021

Had a simular issue, this can be solved by marking the HTML as escaped

Example: Hello '<span class="bold">'{name}'</span>'

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

No branches or pull requests

2 participants