1
votes

I am trying to add React-Native Webview in my existing iOS app, but getting issue Native Module cannot be null. I have tried lot of solutions from online community but yet not fixed the issue.

'use strict';
import React, { Component } from 'react';
import { StyleSheet, View, ScrollView, RefreshControl, WebView, Text} from 'react-native';
export default class Dashboard extends Component {
    render() {
        return (
            <WebView
                originWhitelist={['*']}
                source={{ html: '<h1>Hello world</h1>' }}
            /> 

        );
    }
}

Error:

Unhandled JS Exception: Requiring module "node_modules/react-native/Libraries/Components/WebView/WebView.ios.js", which threw an exception: Invariant Violation: Native module cannot be Unhandled JS Exception: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

2
Can you share the code what you have written, 'coz it would be helpful to other developers to check where the issues would be.Sateesh Yemireddi
Also please share the error what you are getting nowSateesh Yemireddi
'use strict'; import React, { Component } from 'react'; import { StyleSheet, View, ScrollView, RefreshControl, WebView, Text} from 'react-native'; export default class Dashboard extends Component { render() { return ( <WebView originWhitelist={['*']} source={{ html: '<h1>Hello world</h1>' }} /> ); } }sagarchavan
Unhandled JS Exception: Requiring module "node_modules/react-native/Libraries/Components/WebView/WebView.ios.js", which threw an exception: Invariant Violation: Native module cannot be Unhandled JS Exception: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.sagarchavan
You should not add the code to comments directly as per stack overflow policies. Add them in question.Sateesh Yemireddi

2 Answers

0
votes

Try to reinstall the node_modules

rm -rf node_modules && npm install

0
votes

Had this issue and the steps I took were:

1) restart

2) rm -rf node_modules && npm install

3) restart