question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In test ONLY: @react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null.

See original GitHub issue

Bug

The error above happens when running yarn test. The app have been updated with the latest release of 2.2.2. But the tricky is that my app works fine when launching with react-native run-android. I can load the Event component without error.

Environment info

React native info output:

 PS C:\d\code\js\emps_fe> react-native link react-native-device-info
info iOS module "react-native-device-info" is already linked
info Android module "react-native-device-info" is already linked
PS C:\d\code\js\emps_fe> yarn test
yarn run v1.15.2
$ jest
 FAIL  __tests__/App-test.js
  ● Test suite failed to run

    @react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null. To fix this issue try these steps:
      • Run `react-native link react-native-device-info` in the project root.
      • Rebuild and re-run the app.
      • If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
      If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-device-info

      2 | import { SectionList, View, Image, StyleSheet, Text, TouchableOpacity, Platform, TouchableHighlight, AppRegistry } from 'react-native';
      3 | import moment from 'moment';
    > 4 | import DeviceInfo from 'react-native-device-info';
        | ^
      5 | import helper from "../../lib/helper";
      6 | import GLOBAL from "../../lib/global";
      7 |

      at Object.<anonymous> (node_modules/react-native-device-info/deviceinfo.js:19:11)
      at Object.<anonymous> (src/components/event/Event.js:4:1)

 FAIL  __tests__/Event.test.js
  ● Test suite failed to run

    @react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null. To fix this issue try these steps:
      • Run `react-native link react-native-device-info` in the project root.
      • Rebuild and re-run the app.
      • If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
      If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-device-info

      2 | import { SectionList, View, Image, StyleSheet, Text, TouchableOpacity, Platform, TouchableHighlight, AppRegistry } from 'react-native';
      3 | import moment from 'moment';
    > 4 | import DeviceInfo from 'react-native-device-info';
        | ^
      5 | import helper from "../../lib/helper";
      6 | import GLOBAL from "../../lib/global";
      7 |

      at Object.<anonymous> (node_modules/react-native-device-info/deviceinfo.js:19:11)
      at Object.<anonymous> (src/components/event/Event.js:4:1)

Test Suites: 2 failed, 2 total
Tests:       0 total
Snapshots:   0 total
Time:        6.493s
Ran all test suites.
error Command failed with exit code 1.

Library version: x.x.x Here is the package.json: “dependencies”: { “moment”: “^2.24.0”, “react”: “16.8.3”, “react-native”: “0.59.9”, “react-native-cli”: “^2.0.1”, “react-native-confirmation-code-field”: “^3.6.0”, “react-native-device-info”: “^2.2.2”, “react-native-elements”: “^1.1.0”, “react-native-gesture-handler”: “^1.3.0”, “react-native-gifted-chat”: “^0.9.11”, “react-native-keychain”: “^3.1.3”, “react-native-linear-gradient”: “^2.5.4”, “react-native-modal”: “^11.0.2”, “react-native-modal-datetime-picker”: “^7.4.2”, “react-native-paper”: “^2.16.0”, “react-native-segmented-control-tab”: “^3.4.0”, “react-native-vector-icons”: “^6.5.0”, “react-navigation”: “^3.11.0”, “socket.io-client”: “2.1.1” }, “devDependencies”: { “@babel/core”: “^7.4.5”, “@babel/runtime”: “^7.4.5”, “babel-jest”: “^24.8.0”, “jest”: “^24.8.0”, “metro-react-native-babel-preset”: “^0.54.1”, “react-test-renderer”: “16.8.3” },

Steps To Reproduce

Describe what you expected to happen:

Reproducible sample code

Here is the test code:

import ‘react-native’; import React from ‘react’; import App from ‘…/App’;

// Note: test renderer must be required after react-native. import renderer from ‘react-test-renderer’;

it(‘renders correctly’, () => { const tree = renderer.create(<Event />).toJSON(); expect(tree).toMatchSnapshot(); });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:10

github_iconTop GitHub Comments

5reactions
mikehardycommented, May 31, 2020

@tmaly1980 there really should be! I look forward to your contributed mock file pull request and will merge it happily

4reactions
dimlksin2commented, Aug 8, 2019

● Test suite failed to run

@react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null. To fix this issue try these steps:
  • Run `react-native link react-native-device-info` in the project root.
  • Rebuild and re-run the app.
  • If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
  If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-device-info

  1 | import firebase from 'react-native-firebase';
> 2 | import DeviceInfo from 'react-native-device-info';
Read more comments on GitHub >

github_iconTop Results From Across the Web

RNDeviceInfo is null error when running test #636 - GitHub
When running tests with jest, I get the following @react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null.
Read more >
jest : react-native-device-info: NativeModule.RNDeviceInfo is ...
RNDeviceInfo is null. To fix this issue try these steps: The app runs fine in emulator without error. The problem seems with jest...
Read more >
In test ONLY: @react-native-community/react-native-device-info
In test ONLY : @react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null.
Read more >
NativeModule.RNDeviceInfo is NULL - Expo Development Tools
# Bug Trying to use react-native-device-info for the first time and I'm getting… this error when the application tries to start up: node_modules ......
Read more >
react-native-device-info - UNPKG
20, throw new Error(`@react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null. To fix this issue try these steps:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found