user11583965
user11583965

Reputation:

why my app work perfect in debug mode and crash in release mode?

hey there i am new with react native i created an app everything works perfect when i debug it but when i build it it crash in a screen and give me this errors

2019-07-05 12:29:53.403 21905-21925/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules Process: com.foo, PID: 21905 com.facebook.react.common.JavascriptException: Requiring unknown module "./locale/fr"., stack: h@2:1448 d@2:868 Dt@714:16712 Tt@714:17738 Yt@714:16801 n@713:2042 Sn@90:30120 Or@90:45887 na@90:72881 ra@90:73371 Oa@90:80972 Wa@90:80310 Ue@90:83367 De@90:13673 We@90:13846 receiveTouches@90:14605 value@28:3311 @28:822 value@28:2565 value@28:794 value@-1

    at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
    at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
    at android.os.Looper.loop(Looper.java:203)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
    at java.lang.Thread.run(Thread.java:761)

here is my code there two places when i am working with moment here the first one :

import 'moment/locale/fr';
import moment from 'moment';

this.state = { 
      date: moment().locale('fr').format('dddd HH:mm');
}
and set the state to a Text 

the second one is this class

import 'moment/locale/fr';
import moment from 'moment';

componentDidMount() {
   console.log(this.props.hours[0].openAt); 
   const date = new Date();
   const day = date.getDay();
   moment.locale('fr');
   for (let i = 0; i < this.props.hours.length; i++) {
       if (this.props.hours[i].day === day) {
           const format = 'hh:mm';
           const time = moment(date, format);
           const beforeTime = moment(this.props.hours[i].openAt, format);
            const afterTime = moment(this.props.hours[i].closeAt, format);

           if (time.isBetween(beforeTime, afterTime)) {
             this.setState({
                 ouvert: true
             });
           } else {
               this.setState({
                   ouvert: false
               });
           }
       }
   }
   }

Upvotes: 1

Views: 1681

Answers (3)

Stanislau Buzunko
Stanislau Buzunko

Reputation: 1831

Got this error when upgrading from React Native 0.60 to 0.63 and using the latest version of Moment.js (2.29.4). Moment.js worked fine in all components except for the utils file (.fromNow() method particularly)

The error was caused by using moment.locale('fr', {}) for extending the French locale instead of moment.updateLocale('fr', {}).

After switching to updateLocale, the issue was resolved.

Upvotes: 1

codeKnightly
codeKnightly

Reputation: 652

Solved it like this: (In my case i have english and italian localization to enable)

Imported my local localization files as:

import * as en from "./locale/en.json";
import * as it from "./locale/it.json";

Integrated moment localization

var moment = require("moment");
var itLocale = require("moment/locale/it");
var enLocale = require("moment/locale/en-gb");

moment.locale("en", enLocale);
moment.locale("it", itLocale);

Now works on debug/release mode.

Upvotes: 3

Tushar Koul
Tushar Koul

Reputation: 2980

I was facing this issue too and fixed it by downgrading the version of moment to 2.18.1.

If you're using moment-timezone then you would need to add the following in your package.json

"resolutions": {
    "moment-timezone/moment": "2.18.1"
  },

Reference: https://github.com/moment/moment/issues/4216

Upvotes: 1

Related Questions