📅  最后修改于: 2023-12-03 15:04:48.834000             🧑  作者: Mango
This error occurs in React Native when trying to use a feature that relies on Intl
, such as formatting dates or numbers.
The root cause of this error is that the Intl
object is not polyfilled in React Native applications running on Android. This means that any code that uses the Intl
object will fail to execute and return the above error.
The solution to this problem is to manually polyfill the Intl
object in your React Native application.
intl
package using npm
or yarn
.npm install --save intl
Intl
object.import 'intl';
import 'intl/locale-data/jsonp/en'; // add any additional locales you need
Intl
.The intl
package adds support for the Intl
object to your application. It includes a polyfill that ensures that the Intl
object is available even in environments where it is not natively supported.
Importing the intl
and intl/locale-data/jsonp/en
modules ensures that the Intl
object is fully polyfilled in your application. You can also add any additional locales you need by importing their respective modules.
If you're getting the ReferenceError: Can't find variable: Intl
error in your React Native application, it means that you need to manually polyfill the Intl
object. By following the steps outlined above, you can quickly and easily add support for the Intl
object to your application and get your code working again.