16 thoughts on “undefined is not object (evaluating ‘RNDeviceInfo.deviceId’)

  1. Same issue here for iOS

    2016-07-21 13:57:23.197 [error][tid:com.facebook.react.JavaScript] undefined is not an object (evaluating 'RNDeviceInfo.uniqueId')
    

    I installed it via rnpm

  2. As @jorge8989 said, after running react-native link react-native-device-info error’s gone. However you have to restart the app after running this, quit the simulator and then run react-native run-ios again.

  3. Had the same issue (runnig on ios real device) and re-linking solved that for me, why “relinking”? cause apparently my first trying to link it manually effected so I ran: react-native unlink react-native-device-info and afterwards react-native link react-native-device-info

  4. I had the same problem.The solve way I use is:
    Open your Xcode or AndroidStudio,then clean and build your project,last run app.

  5. make sure your android file MainApplication.java, have RNDeviceInfo()

    +import com.learnium.RNDeviceInfo.RNDeviceInfo;
    
    ...
     @Override
        protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
    +         new RNDeviceInfo(),
              new MainReactPackage()
          );
        }
    
    
    
  6. react-native link OR react-native link react-native-device-info.
    @Lawrence23
    After that close any previously running react packager. Don’t just simply reload the app.

    Now run it. This fixed in my case.

  7. For those facing this on iOS, the complete steps for me were to:

    Shut down packager
    Uninstall app from simulator
    Shut down simulator
    Run react-native unlink react-native-device-info
    Run react-native link react-native-device-info
    Open project in Xcode, clean and build
    Start packager react-native-start
    Start the simulator react-native run-ios --simulator "iPhone 8 Plus" or whichever simulator you use

    It then worked no problem. Really not sure what the actual issue was, my guess is that the package was not properly linked. (I always use react-native link)

  8. Thanks @bencodezen for the workaround, my code snippet for those trying to use react-native-device-info with Expo

        var deviceSerial =0;
        try {
            if(Expo.Constants.appOwnership == 'expo')
            {
                console.log('Running in expo');
                deviceSerial = Expo.Constants.deviceId;
            }
            else
            {
                var DeviceInfo = require('react-native-device-info');
                deviceSerial = DeviceInfo.getUniqueID();
            }
             console.log('DEVICE ID FOUND: '+deviceSerial);
        }
        catch(e)
        {
            console.log('error reading device ID');
            deviceSerial =1;
        }
    
  9. For anyone still having this issue even after following the manual linking steps.

    • Go to MainApplication.java
    • Delete new RNDeviceInfo() from getPackages()
    • Add RNDeviceInfo() inside createAdditionalReactPackages()

    In case you don’t have createAdditionalReactPackages() in your MainApplication.java, here is the code:

    public class MainApplication extends NavigationApplication {
        ...
        @Override
        public List<ReactPackage> createAdditionalReactPackages() {
            return Arrays.<ReactPackage>asList(
                    // eg. new VectorIconsPackage()
                    new RNDeviceInfo()
            );
        }
        ....
    }
    

13 thoughts on “undefined is not object (evaluating ‘RNDeviceInfo.deviceId’)

  1. As @jorge8989 said, after running react-native link react-native-device-info error’s gone. However you have to restart the app after running this, quit the simulator and then run react-native run-ios again.

  2. I had the same problem.The solve way I use is:
    Open your Xcode or AndroidStudio,then clean and build your project,last run app.

  3. make sure your android file MainApplication.java, have RNDeviceInfo()

    +import com.learnium.RNDeviceInfo.RNDeviceInfo;
    
    ...
     @Override
        protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
    +         new RNDeviceInfo(),
              new MainReactPackage()
          );
        }
    
    
    
  4. I am using Expo and none of the above solutions worked for me. I am using Expo to create a standalone iOS app

  5. For those facing this on iOS, the complete steps for me were to:

    Shut down packager
    Uninstall app from simulator
    Shut down simulator
    Run react-native unlink react-native-device-info
    Run react-native link react-native-device-info
    Open project in Xcode, clean and build
    Start packager react-native-start
    Start the simulator react-native run-ios --simulator "iPhone 8 Plus" or whichever simulator you use

    It then worked no problem. Really not sure what the actual issue was, my guess is that the package was not properly linked. (I always use react-native link)

  6. Thanks @bencodezen for the workaround, my code snippet for those trying to use react-native-device-info with Expo

        var deviceSerial =0;
        try {
            if(Expo.Constants.appOwnership == 'expo')
            {
                console.log('Running in expo');
                deviceSerial = Expo.Constants.deviceId;
            }
            else
            {
                var DeviceInfo = require('react-native-device-info');
                deviceSerial = DeviceInfo.getUniqueID();
            }
             console.log('DEVICE ID FOUND: '+deviceSerial);
        }
        catch(e)
        {
            console.log('error reading device ID');
            deviceSerial =1;
        }