-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
if no manual explicit id is added: [React Intl] An id
must be provided to format a message.
#1901
Comments
Thanks a lot for reporting. https://formatjs.io/docs/guides/bundler-plugins should have the details on how to fix that. I'll revisit the doc to make it clearer. |
thanks Long Ho, didn't realise this |
@longlho I'm facing the same problem. It should produce a dynamic id if I omit explicit id but it throws the flowing error I have tried to run this example from the docs but it's not working although explicit ids are discouraged in the docs. Here are my source codes you may check |
@mdshifut I had the same problem and I finally made it work. In my case I was using
After some researching I found the solution. You have to install
After that, create a file in the root of the project named const { addBabelPlugins, override } = require('customize-cra');
module.exports = override(
...addBabelPlugins([
'react-intl',
{
idInterpolationPattern: '[sha512:contenthash:base64:6]',
extractFromFormatMessageCall: true,
ast: true,
},
])
); And with that the |
Having the same problem on CRA. @luismasserral 's solution doesn't work either. I've even tried ejecting CRA and config babel explicitly but it still tell me id must be provided. |
Do you have a repro? |
Hi @AVAVT , I solve this problem using customize-cra, and react-app-rewired packages. You can override the babel configuration using those packages. |
@mdshifut Yes, I have tried that, but it doesn't work. You can see the repo below where I applied that solution without success.
@longlho Sorry it took so long to reply. I had to strip down the confidential codes. Here's the repo: https://github.com/AVAVT/reactintl-test I've only added a test
|
@AVAVT can u create a separate GH issue? |
Is there any way to solve this without using react-app-rewired? Or is there something planned that will allow us to use auto-generated ids natively in the future? |
@florianmartens can u clarify |
Hey @longlho, thanks for the answer. I think that cra is the most popular react boilerplate and obviously you have no influence on their Babbel config. I think having auto-generated keys has a lot of advantages - so I'd love to use that option. At the same time, I'm hesitant to use Maybe the extract script could just check if |
The issue is that extraction cannot modify the transpilation process which CRA controls, thus cannot inject IDs. |
Stumbled upon this when looking for ways to setup a project not using create-react-app to alow for the simple Could you please provide a link to a demo/code sandbox/documentation which shows what babel configuration should support the short defineMessages() syntax for use cases of frontend app using react, babel and webpack? |
Hmm we don't support declaring messages with just key value |
Has there been any update on this? I've tried both solutions updating .babelrc as described in https://formatjs.io/docs/guides/bundler-plugins/ as well as override in config-overrides.js which didn't help so now my only solution is to add the ids manually |
@kkuzmina are you using |
@longlho Originally used |
Do u have a reproducible repo? |
@kkuzmina |
Hi, does anyone know if there is a solution using craco?
|
Hello, I have the same issue mentioned above but none of the soutions proposed worked for me. Can you please have a look into my repo? I have no idea waht to do more :( Please help thank you |
Which package?
react-intl
Describe the bug
Following the steps in the docs results in an error:
https://formatjs.io/docs/getting-started/message-distribution
To Reproduce
Steps to reproduce the behavior:
formatjs extract 'src/**/*.ts*' --out-file src/lang/en.json
formatjs compile 'src/lang/en.json' --ast --out-file src/lang/compiled/en.json && formatjs compile 'src/lang/fr.json' --ast --out-file src/lang/compiled/fr.json
bootstrapApplication
It is fixed if I manually add an id to the message, but the docs state that this is discouraged
The text was updated successfully, but these errors were encountered: