You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React-Native导入WebView报错:模块无该导出成员TS2305

解决React Native中WebView导入的TypeScript错误

问题原因

React Native 0.60及以上版本中,WebView组件已从核心的react-native模块移除,需使用独立第三方库react-native-webview。

解决步骤

  • 安装react-native-webview依赖
    使用npm:

    npm install react-native-webview
    

    或者yarn:

    yarn add react-native-webview
    
  • 针对iOS项目执行Pod同步(RN 0.60+支持自动链接,但iOS需同步Pod依赖)

    cd ios && pod install && cd ..
    
  • 修改代码中的导入语句
    将原有导入代码:

    import {WebView} from 'react-native';
    

    替换为:

    import WebView from 'react-native-webview';
    

修改后的完整代码示例

import React, {Component} from 'react';
import WebView from 'react-native-webview';

class MyWeb extends Component {
  render() {
    return (
      <WebView
        source={{
          uri: 'https://github.com/facebook/react-native',
        }}
        style={{marginTop: 20}}
      />
    );
  }
}

内容的提问来源于stack exchange,提问作者HelloCH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 00:57:25