首页 > 解决方案 > 添加 Webviews 后 React-Native Native 模块不能为空

问题描述

我正在尝试在我现有的 iOS 应用程序中添加 React-Native Webview,但遇到问题 Native Module 不能为空。我已经尝试了许多来自在线社区的解决方案,但仍未解决此问题。

'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>' }}
            /> 

        );
    }
}

错误:

未处理的 JS 异常:需要模块“node_modules/react-native/Libraries/Components/WebView/WebView.ios.js”,这引发了异常:不变违规:本机模块不能是未处理的 JS 异常:不变违规:元素类型无效:期望一个字符串(用于内置组件)或一个类/函数(用于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。

标签: iosreact-native

解决方案


尝试重新安装node_modules

rm -rf node_modules && npm install


推荐阅读