admin管理员组

文章数量:1253715

The react-native project I'm working on already use react-native-device-info. When I tried to add Android-${DeviceInfo.getUniqueID()} to a header in a request, I get this error:

  { TypeError: DeviceInfo.getUniqueID is not a function
        at makeRequest (~/code/rn/src/services/api-client.js:46:39)

How can that be? I import it like this on the top of the files it is used in.

import * as DeviceInfo from 'react-native-device-info';

If I change the import statement to import DeviceInfo from 'react-native-device-info';, then I get this error:

TypeError: _reactNativeDeviceInfo2.default.getUniqueID is not a function

export function makeRequest(endpoint, method, token, csrfToken = null, body = null) {
    const config = {
        method,
        credentials: 'same-origin',
        headers: {
            Applikasjon: 'KONSERNAPP',
            Accept: 'application/json',
            'X-App-Version': `Android-${DeviceInfo.getUniqueID()}`,
            'Content-Type': 'application/json',
            token,
        },
        timeout: 120000,
    };

The react-native project I'm working on already use react-native-device-info. When I tried to add Android-${DeviceInfo.getUniqueID()} to a header in a request, I get this error:

  { TypeError: DeviceInfo.getUniqueID is not a function
        at makeRequest (~/code/rn/src/services/api-client.js:46:39)

How can that be? I import it like this on the top of the files it is used in.

import * as DeviceInfo from 'react-native-device-info';

If I change the import statement to import DeviceInfo from 'react-native-device-info';, then I get this error:

TypeError: _reactNativeDeviceInfo2.default.getUniqueID is not a function

export function makeRequest(endpoint, method, token, csrfToken = null, body = null) {
    const config = {
        method,
        credentials: 'same-origin',
        headers: {
            Applikasjon: 'KONSERNAPP',
            Accept: 'application/json',
            'X-App-Version': `Android-${DeviceInfo.getUniqueID()}`,
            'Content-Type': 'application/json',
            token,
        },
        timeout: 120000,
    };
Share Improve this question edited Oct 16, 2018 at 9:18 David Schumann 14.8k13 gold badges83 silver badges105 bronze badges asked Oct 19, 2017 at 13:08 martinsmartins 10k12 gold badges64 silver badges88 bronze badges 4
  • have you solved this issue in the meantime? – David Schumann Commented Oct 16, 2018 at 9:18
  • I can't really remember. I think I solved it in a hackish workaround. – martins Commented Oct 16, 2018 at 11:16
  • 2 If you encounter anything like that in version 3.0.0, try to revert to 2.3.2. – Jonas Sourlier Commented Sep 12, 2019 at 18:44
  • 1 same problem when updated today, yarn add [email protected] to downgrade – Jose V Commented Sep 13, 2019 at 21:44
Add a ment  | 

3 Answers 3

Reset to default 8

since react-native-device-info is upgraded to 4.x.x its method typo is bit changed, it is now accepting DeviceInfo.getUniqueId() instead of DeviceInfo.getUniqueID()

This solved it for me DeviceInfo.getUniqueId() instead of DeviceInfo.getUniqueID(). Lolz. It's a typo in the documentation

Downgrading:

-> yarn add [email protected]

then use DeviceInfo.getUniqueID()

Working for me.

本文标签: javascriptDeviceInfogetUniqueID is not a functionStack Overflow