5

I'm migrating react-intl to version 3.0, and need to polyfill locale-data for IE. Specifically I want to load a polyfill of locale data for en-US. I can only find @formatjs/intl-relativetimeformat/dist/locale-data/en locale file.

if (!Intl.RelativeTimeFormat) {
  // eslint-disable-next-line global-require
  require('@formatjs/intl-relativetimeformat/polyfill');
  // eslint-disable-next-line global-require
  require('@formatjs/intl-relativetimeformat/dist/locale-data/en-US');
}

It leads to this error :

Module not found: Error: Can't resolve '@formatjs/intl-relativetimeformat/dist/locale-data/en-US' in '/xxx/xxx/xxx/xxx/app'

Ant1
  • 344
  • 5
  • 12
  • A member of formatjs replied to me that the file `@formatjs/intl-relativetimeformat/dist/locale-data/en` contains en-US locale. See https://github.com/formatjs/react-intl/issues/203#issuecomment-531168939 – Ant1 Sep 13 '19 at 12:41

3 Answers3

4

Try the below format in "@formatjs/intl-relativetimeformat": "^7.2.0",

import '@formatjs/intl-pluralrules/polyfill'
import '@formatjs/intl-pluralrules/locale-data/en'
import '@formatjs/intl-pluralrules/locale-data/de'

import '@formatjs/intl-relativetimeformat/polyfill'
import '@formatjs/intl-relativetimeformat/locale-data/en'
import '@formatjs/intl-relativetimeformat/locale-data/de'

and addLocaleData is no removed already as per https://formatjs.io/docs/react-intl/upgrade-guide-3x/#migrate-to-using-native-intl-apis

Zhihong LU
  • 143
  • 1
  • 4
3

try to install :

npm i @formatjs/intl-relativetimeformat
0

I had this same exact issue, when I checked the @formatjs directory inside node_modules/ there was no dist directory @formatjs/intl-relativetimeformat/**dist/**locale-data/en so I removed it from the import and everything worked fine.

Punter Bad
  • 473
  • 7
  • 14