React-native-device-info: Getting undefined is not an object: reactNativeDeviceInfo.DeviceInfo.getAPILevel is

Created on 12 Feb 2018  路  5Comments  路  Source: react-native-device-info/react-native-device-info

Summary

I have recently upgraded to RN: 0.45.1, react-native-device-info: 0.15.1, and whenever I try to query for api level the app crashes with an error.

| | |
| ----------- | --- |
| Version | 0.15.1 |
| Affected OS | Android |
| OS Version | 8.0.0 |

Current behavior

Getting this error in sentry:

undefined is not an object (evaluating 'reactNativeDeviceInfo.DeviceInfo.getAPILevel')

This was working in previous version of RN 44.0 and react-native-device-info: 0.13.0

Expected behavior

getAPILevel should give the api level

android invalid

Most helpful comment

Thanks @machour , sorry I noticed that as it was working in other components of my app, in one particular component i was importing it in an incorrect way:

// incorrect way
import { DeviceInfo } from 'react-native-device-info'`;

// correct way
import DeviceInfo from 'react-native-device-info';

All 5 comments

Hi @sahil290791, it seems like you forgot to link the library.
Can you try react-native link react-native-device-info?

I have linked the library and checked the manual linking steps also. Tried unlinking and linking it again.

This is obviously a linking problem as reactNativeDeviceInfo.DeviceInfo seems to be undefined.

Thanks @machour , sorry I noticed that as it was working in other components of my app, in one particular component i was importing it in an incorrect way:

// incorrect way
import { DeviceInfo } from 'react-native-device-info'`;

// correct way
import DeviceInfo from 'react-native-device-info';

No problems, thank you for reporting back!

Was this page helpful?
0 / 5 - 0 ratings