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

Flutter报错:类AppJsImpl未定义delete方法

解决 Firebase Database Web 包方法未定义错误

问题原因

你使用的firebase_database_web: 0.2.0+15版本过于陈旧,与最新版firebase_core存在API兼容性冲突——旧版本包尝试调用的delete方法,在新版Firebase JS SDK对应的interop层中已被移除或重命名,导致类AppJsImpl中找不到该方法。

解决方案

  • 升级Firebase Database相关依赖
    在pubspec.yaml中更新firebase_database到最新稳定版,它会自动匹配兼容的firebase_database_web版本,解决API不兼容问题:

    dependencies:
      firebase_core: ^latest_version # 保留你当前使用的最新版
      firebase_database: ^latest_version # 替换为当前最新稳定版,例如^1.0.5
    
  • 清理缓存并重新拉取依赖
    执行以下命令确保依赖完全更新:

    flutter clean
    flutter pub get
    
  • 确认初始化代码正确性
    保持标准的Firebase初始化写法即可,无需额外修改:

    import 'package:firebase_core/firebase_core.dart';
    import 'firebase_options.dart';
    
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      runApp(MyApp());
    }
    
  • 临时降级方案(不推荐)
    若升级后仍有问题,可临时将firebase_core降级到与旧版firebase_database_web兼容的版本,但这只是权宜之计,长期建议保持所有Firebase相关包版本同步更新。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 05:36:22