-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Error when using FormattedMessage in a module where IntlProvider is created by project #1909
Description
Which package?
I think it's react-intl
Describe the bug
I have a module (library) and a project that uses this library. Both are written in TypeScript for what it's worth.
In the project I add a top-level IntlProvider, and then add a component from the library which adds a FormattedMessage.
I get the error:
Error: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
I imagine this might mean that the library can't find IntlProvider because it doesn't recognize the React DOM tree, but I specifically added react as external when packing the library, and furthermore I am able to add other DOM elements (not FormattedMessage).
To Reproduce
I was able to create a small repo that repros the issue.
<cd somewhere>
git clone https://github.com/chakaz/repro-repo .
cd repro-lib
npm install
npm run build:dev
cd ../project
npm install
npm run start
Expected behavior
no error to be printed (other than no messages found), but I get:
Error: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
Which is especially annoying since console has the following log:
The above error occurred in the <Context.Consumer> component:
in FormattedMessage
in h2
in div
in Loading (at App.tsx:11)
in IntlProvider (at App.tsx:8)
in App (at src/index.tsx:9)
in StrictMode (at src/index.tsx:8)
Desktop (please complete the following information):
- Linux
- Chrome
Will really appreciate any help!