React Native, Invariant Violation: Native module cannot be null.
See original GitHub issueš Bug Report
hey, hi! i have a similar issue (i think) here: https://github.com/facebook/jest/issues/2208, but this issue is quite old, and i have followed the solutions there, but none worked for me.
at first, i encountered this error for running jest
:
/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native-onesignal/index.js:4
import { NativeModules, NativeEventEmitter, NetInfo, Platform } from 'react-native';
^^^^^^
SyntaxError: Unexpected token import
> 1 | import OneSignal from 'react-native-onesignal';
2 |
3 | export const STORE_TIMEFRAME = 'STORE_TIMEFRAME';
4 | export const STORE_TIMEFRAMES = 'STORE_TIMEFRAMES';
at ScriptTransformer._transformAndBuildScript (../../../../../usr/lib/node_modules/jest-cli/node_modules/jest-runtime/build/script_transformer.js:316:17)
at Object.<anonymous> (src/actions/subscription.js:1:387)
at Object.<anonymous> (src/reducers/subscription.js:1:402)
so i went ahead and added react-native-onesignal
to package.json
as such:
"transformIgnorePatterns": [
"node_modules/(?!(react-native-onesignal|react-native-login|react-native-elements)/)"
]
so that solved my problem. but here comes another problem:
Invariant Violation: Native module cannot be null.
> 1 | import OneSignal from 'react-native-onesignal';
2 |
3 | export const STORE_TIMEFRAME = 'STORE_TIMEFRAME';
4 | export const STORE_TIMEFRAMES = 'STORE_TIMEFRAMES';
at invariant (node_modules/fbjs/lib/invariant.js:42:15)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:37:31)
at Object.<anonymous> (node_modules/react-native-onesignal/index.js:9:33)
i tried mocking OneSignal
, but this is what happens when I do that:
Cannot find module 'OneSignal' from 'Main.test.js'
> 1 | import React from 'react'
2 | import { shallow } from '../../jest-setup'
3 | import configureStore from 'redux-mock-store'
4 | import OneSignal from 'react-native-onesignal'
at Resolver.resolveModule (../../../../../usr/lib/node_modules/jest-cli/node_modules/jest-resolve/build/index.js:169:17)
at Object.<anonymous> (src/__tests__/Main.test.js:1:108)
To Reproduce
Steps to reproduce the behavior:
- npm install react-native-onesignal
- run jest
Expected behavior
test passes, writes a snapshot
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Invariant Violation: Native module cannot be null #43 - GitHub
At iOS, it builds successfully, however, when the app starts, I get this error: Invariant Violation: Native module cannot be null.
Read more >React-native, "Native module cannot be null" - Stack Overflow
To solve this, your Project Navigator -> Target -> General -> Linked Frameworks and Libraries, make sure somelib.a is there. enter image description...
Read more >Invariant Violation: Native module cannot be null. on Managed ...
SDK Version: 41.0.0; Platforms(Android/iOS/web/all): Android/ios. I upgraded to SDK 41 yesterday and worked out some smaller issues beforeĀ ...
Read more >" has not been registered" and "Invariant Violation: Native ...
I am working on a project in React Native using Expo and Firebase. ... and "Invariant Violation: Native module cannot be null" errorsĀ ......
Read more >React Native Ios: Native Module cannot be null - iTecNote
This usually happens when you fail to link the third lib to your target causing NativeModules find nothing at attempt. To solve this,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, you need to mock the
react-native-onesignal
, notOneSignal
. Mocking is for modules andOneSignal
is not a module - itās a variable name.should do the trick
Hi, Iām a having an issue while running my app āInvariant Violation: Native module cannot be nullā
Can someone please help for that Thanks