-
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
Better error message for: Invariant Violation: [React Intl] An id
must be provided to format a message.
#1059
Comments
Can you be a little more specific about your problem? Locale is set on
Maybe I'm missing which API call you are thinking of and you can share... |
I think what everybody desires is more detailed Error info when non-existing id is provided to FormattedMessage, intl.formatMessage, etc. Current error message when something got screwed: Desired error message: Is this actually doable or am i missing something? Thanks |
For anyone that lands here, this can be caused by your message key not existing in your |
Any updates on this? Would be very helpful. |
I'm also have this issue. It happens when I'm trying to define a template string in my "de" locale file.
I don't need to have ID because I want to have exactly this defaultMessage to interpolate but it looks like there is no any other way to do it without this unnecessary ID. It's very annoying. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This isn't stale, it's just a request that hasn't seen any action. |
The id is used as a lookup to find the message, so as of right now it’s required. If there is no ID supplied it’s hard to know what info to give. I’ve marked this as an enhancement so stalebot doesn’t close it again. But unless someone offers to help this probably will not get resolved. |
我遇到了同样的问题,但是由于代码的复杂,我并不知道其发生的细节与错误的定位,希望能提示更详细的错误,感谢 |
I feel this is a really important issue. Often I'm dealing with huge files and somewhere in there a missing ID causes the page to occasionally crash. Tracking down which ID is missing is really frustrating and something I regularly deal with. The only solution seems to be extensive manual testing |
What’s your workflow? We have a linter that can address that
…On Sat, Jan 4, 2020 at 4:10 AM Nathan ***@***.***> wrote:
I feel this is a really important issue. Often I'm dealing with huge files
and somewhere in there a missing ID causes the page to occasionally crash.
Tracking down which ID is missing is really frustrating and something I
regularly deal with. The only solution seems to be extensive manual testing
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1059>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABQM34D3BIQSOEJBASAHVLQ4BHANANCNFSM4ECCRV4Q>
.
|
@longlho curious to know which linter you're referring to 😄 Is it this one https://github.com/calm/eslint-plugin-react-intl? |
This is the one I'm referring to: https://www.npmjs.com/package/eslint-plugin-formatjs :) |
@longlho is it possible to provide some more information on where the issue may be located as @jdolinski1 suggested? I'd be happy to make a PR with changes!
|
Our latest version has a proper stack trace & error code now |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The page hasn't been displayed when I accessed it the first time and I need to refresh it to display the compoents. How can I fix that issue? |
@slim-hmidi please create another GH issue w/ repro link |
I'm currently getting this message in node and I'm trying to figure out what I'm doing wrong. const { createIntl, createIntlCache } = require("@formatjs/intl");
const cache = createIntlCache();
const msgObj = {
locale: 'en-US',
messages: {
a6AoNm: [ { type: 0, value: 'bla' } ],
},
defaultLocale: 'en-US'
}
const intl = createIntl(msgObj, cache);
intl.formatMessage({defaultMessage: "bla"}); my stack trace Error: [@formatjs/intl] An `id` must be provided to format a message.
at Object.invariant (/Users/user/Projects/project/node_modules/@formatjs/ecma402-abstract/utils.js:87:15)
at formatMessage (/Users/user/Projects/project/node_modules/@formatjs/intl/src/message.js:34:24)
at Object.<anonymous> (/Users/user/Projects/project/src/bla/bla.js:8:6)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/user/Projects/project/scripts/bla/bla.js:16:22) Any ideas how to fix this? |
Did you add our babel-plugin-formatjs? |
No. Is this how I'd do it? |
In that case you can use https://formatjs.github.io//docs/tooling/linter enforce-id option and it'll autofix it. Otherwise you can transpile your code with either typescript or babel. |
Thanks for the tip. I got it working with this minimal $ node --version
v14.16.0 module.exports = {
root: true,
parserOptions: {
ecmaVersion: 9 // depends on your version of nodejs
},
plugins: ["formatjs"],
rules: {
"formatjs/enforce-id": [
"error",
{
idInterpolationPattern: "[sha512:contenthash:base64:6]"
}
]
}
}; $ eslint \"src/**\" -c ./.eslintrc.js --fix Now regarding this issue. I think many users of formatjs arrive at this issue from Google. I can only speak for myself, but I wish formatjs would have reminded me about configuring babel or eslint. However, from my stack trace, I rather concluded that something must be wrong with e.g. my messages file. Could format js thrown an error to inform the user to install e.g. an id enforcer like babel or eslint when it's clear that e.g. the messages file is not the issue? |
yup good idea. I've clarified the err message |
does it mead that every time during development I have to run eslint --fix ? |
U can setup ur ide to fix on save |
Is this a BUG REPORT or FEATURE REQUEST? (choose one)
Feature.
If this is a FEATURE REQUEST, please:
-->
Something I forget implement the default locale or maybe misspell one of them, in this hole I will get a notice like:
Invariant Violation: [React Intl] An id must be provided to format a message.
However, I think the message could be more helpful if we supply exactly what the missing attribute is, right?
p.s. I have not read the code yet so I do not know if this is doable or not, but if it is I am glad to submit a PR for this.
Expected behavior
Supply with a more detailed message, maybe:
Invariant Violation: [React Intl] An 'id' must be provided to format a message for key 'missLocaleKey'.
The text was updated successfully, but these errors were encountered: