Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invariant Violation: Native module cannot be null. with "preset": "react-native", #2382

Closed
jcollum opened this issue Dec 20, 2016 · 9 comments

Comments

@jcollum
Copy link
Contributor

jcollum commented Dec 20, 2016

Repo: https://github.com/jcollum/kishar-nine/tree/05-testing

Related (closed) #2208

$ versions
npm 3.10.8
node v6.9.1
OS:
ProductName:	Mac OS X
ProductVersion:	10.11.6
BuildVersion:	15G31
$ cat package.json 

    "react-native": "~0.39.1",
...
 "jest": {
    "preset": "react-native",
    "testRegex": "./test/.*.js$"
  },
  "devDependencies": {
...
    "jest": "~18.0.0",

$ npm test

> [email protected] test /Users/collumj/research/kishar-nine
> jest

 FAIL  test/index.android.js
  ● Test suite failed to run

    Invariant Violation: Native module cannot be null.
      
      at invariant (node_modules/fbjs/lib/invariant.js:38:15)
      at Linking.NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
      at new Linking (node_modules/react-native/Libraries/Linking/Linking.js:119:141)
      at Object.<anonymous> (node_modules/react-native/Libraries/Linking/Linking.js:191:16)
      at Object.get Linking [as Linking] (node_modules/react-native/Libraries/react-native/react-native.js:91:22)
      at Object.<anonymous> (node_modules/react-native-experimental-navigation/NavigationRootContainer.js:15:36)

The test is pretty simple:

$ cat test/index.android.js 
import 'react-native';
import React from 'react';
import Index from '../index.android.js';

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

it('renders correctly', () => {
  const tree = renderer.create(
    <Index />
  );
});

Steps to reproduce:

  1. git clone https://github.com/jcollum/kishar-nine.git k9fresh
  2. cd k9fresh/
  3. git checkout 05-testing && npm install && npm test

The tests work on the 00 branch but since upgrading react and jest they fail and in a very cryptic way. They don't appear to be actually running.

@cpojer
Copy link
Member

cpojer commented Dec 20, 2016

Did they fail because of the react or because of the Jest update?

@jcollum
Copy link
Contributor Author

jcollum commented Dec 20, 2016

$ gd b1d14..041841 package.json
diff --git a/package.json b/package.json
index 030296e..1b7a9f7 100644
--- a/package.json
+++ b/package.json
@@ -20,16 +20,12 @@
   },
   "jest": {
     "preset": "react-native",
-    "globals": {
-      "__DEV__": true
-    },
-    "testRegex": "./test/.*.js$",
-    "rootDir": "."
+    "testRegex": "./test/.*.js$"
   },
   "devDependencies": {
     "babel-jest": "17.0.2",
     "babel-preset-react-native": "1.9.0",
-    "jest": "17.0.3",
+    "jest": "~18.0.0",
     "react-test-renderer": "15.4.1"
   }
 }

Looks like jest. That stuff in there with globals and rootDir made no difference, still failing.

@thymikee
Copy link
Collaborator

Have you tried using babel-jest v18?

@jcollum
Copy link
Contributor Author

jcollum commented Dec 20, 2016

Yes, just did:

$ cat node_modules/babel-jest/package.json | grep version
        "type": "version"
    "type": "version"
  "version": "18.0.0"

collumj@por-collumj-m ~/research/kishar-nine (05-testing) 12:02:12  
$ npm test

> [email protected] test /Users/collumj/research/kishar-nine
> jest

 FAIL  test/index.ios.js
  ● Test suite failed to run

    Invariant Violation: Native module cannot be null.
      
      at invariant (node_modules/fbjs/lib/invariant.js:38:15)

@jcollum
Copy link
Contributor Author

jcollum commented Dec 20, 2016

Did a full wipe of node_modules, install and test with this package.json:

"dependencies": {
    "lodash": "~4.17.2",
    "react": "15.4.1",
    "react-native": "~0.39.1",
    "react-native-router-flux": "~3.37.0",
    "react-redux": "~4.4.6",
    "redux": "~3.6.0",
    "redux-thunk": "~2.1.0"
  },
  "jest": {
    "preset": "react-native",
    "testRegex": "./test/.*.js$"
  },
  "devDependencies": {
    "babel-jest": "~18.0.0",
    "babel-preset-react-native": "1.9.1",
    "jest": "~18.0.0",
    "react-test-renderer": "15.4.1"
  }

Same result.

@thymikee
Copy link
Collaborator

Are you sure your tests works on Jest 17?
I've just checkout your branch, check Jest 18 and 17 and both throw the same error.

@jcollum
Copy link
Contributor Author

jcollum commented Dec 21, 2016

Did you downgrade RN at the same time? I think that may be where the problem lies:

$ rm -rf node_modules/ && git checkout 02-routing && npm install --quiet && npm test

All tests pass.

Do the same with 03-redux-counter and both tests fail for the Invariant error. Diff the package.json between the two and you see:

$ git diff 02-routing...03-redux-counter package.json
...
-    "react-native": "0.38.0"
+    "react-native": "~0.39.1",

So, should I close this and open it on RN?

@thymikee
Copy link
Collaborator

Nope, no changes besides Jest. I think RN repo will be a better place to tackle this. Thanks!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants