Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native after Expo Eject errors with NSString cannot be converted to NSNumber

I first had an Expo managed project, but since I needed to add a Subscription service, I had to eject it. Everything was going fine while it was managed by Expo. Now, my app can be opened with "expo start" which opens the App in the iOS Simulator and I do not have any error messages. Everything works as expected. The problem occurs when I build is as a Native App, it errors out with

JSON value '3000' of type NSString cannot be converted to NSNumber

+[RCTConvert NSNumber:]
    RCTConvert.m:60
+[RCTConvert double:]
RCTBridgingToDouble(objc_object*)
JS::NativeNetworkingIOS::SpecSendRequestQuery::timeout() const
-[RCTNetworking sendRequest:callback:]
__invoking___
-[NSInvocation invoke]
-[NSInvocation invokeWithTarget:]
-[RCTModuleMethod invokeWithBridge:module:arguments:]
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread

I tried to search for the value "3000" in my project but couldn't find anything. I know somehow it provides the number 3000 somewhere as a string which cannot be converted to a number. And again, this problem only occurs as a native build. Expo is working just fine. I also don't know at the moment how I would go about debugging this...

like image 955
Devchris Avatar asked Dec 01 '25 09:12

Devchris


1 Answers

I finally solved the mystery. Posting the answer here for anyone else who is running into this issue.

If you do have an expo managed project and you ejected it and you get an error after with NSString cannot be converted to NSNumber for iOS or java.lang.String cannot be cast to java.lang.double check your .env file. In my case I set API_REQUEST_TIMEOUT = '3000' and used it for axios

const instance = axios.create({
  baseURL: API_URL,
  timeout: API_REQUEST_TIMEOUT,
});

The 3000 didn't appear in my search because it's in my .env file. And this error message went away because I believe when activated the network inspect in the react native debugger, it will override the request timeout. Just a heads up to double check your .env file if you run into this problem.

The Fix:

const instance = axios.create({
  baseURL: API_URL,
  timeout: 3000,
});

Note here that the timeout value does not get passed as a string.

like image 184
Devchris Avatar answered Dec 05 '25 09:12

Devchris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!