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

Flutter Web调试版运行报错TypeError:ArgumentError无法转为JavaScriptObject

Flutter Web调试模式抛出TypeError错误求助

Web端应用此前正常运行,近期启动调试版本时持续抛出TypeError错误,核心报错信息为:Error: TypeError: Instance of 'ArgumentError': type 'ArgumentError' is not a subtype of type 'JavaScriptObject',报错栈指向_flutterfire_internals相关代码。

报错日志

Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:54101/Qknz_K4xs_g=/ws
Debug service listening on ws://127.0.0.1:54101/Qknz_K4xs_g=/ws
Debug service listening on ws://127.0.0.1:54101/Qknz_K4xs_g=/ws
Error: TypeError: Instance of 'ArgumentError': type 'ArgumentError' is not a subtype of type 'JavaScriptObject'
dart:sdk_internal 11932:11                                                    throw_
dart:sdk_internal 24589:15                                                    _failedAsCheck
dart:sdk_internal 24575:14                                                    _generalAsCheckImplementation
app/packages/_flutterfire_internals/_flutterfire_internals.dart.lib.js 70:38  _testException
dart:sdk_internal 49595:59                                                    runUnary
dart:sdk_internal 44726:29                                                    matchesErrorTest
dart:sdk_internal 45337:30                                                    handleError
dart:sdk_internal 45364:17                                                    _propagateToListeners
dart:sdk_internal 45207:23                                                    [_completeError]
dart:sdk_internal 45250:31                                                    callback
dart:sdk_internal 50044:13                                                    _microtaskLoop
dart:sdk_internal 50050:13                                                    _startMicrotaskLoop
dart:sdk_internal 45591:9                                                     <fn>
Application finished.

Flutter环境信息

[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
    • Flutter version 3.19.6 on channel stable at /Users/canyon/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (2 days ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/canyon/Library/Android/sdk
    • Platform android-34, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.86.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.82.0

[✓] Connected device (3 available)
    • iPhone 15 Pro (mobile) • 9E000980-FB8A-459B-86AD-0AECD6B15485 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 124.0.6367.61
    ! Error: Browsing on the local area network for Canyon's Developer iPhone. Ensure the device is unlocked and attached with a cable or associated with the same
      local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for Canyon's iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area
      network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for Canyon’s Apple Watch. Ensure the device is unlocked and discoverable via Bluetooth. (code -27)
    ! Error: Browsing on the local area network for DavidiPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area
      network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

已执行的排查操作

  • 移除了所有不兼容Web的pub依赖
  • 执行了flutter clean命令
  • 更新了所有pub依赖
  • 搜索相关问题但未找到匹配案例

可能的解决方向

  1. 锁定FlutterFire依赖版本
    报错栈指向_flutterfire_internals,大概率是FlutterFire相关包的版本兼容问题。将所有FlutterFire依赖(如firebase_core、firebase_auth等)锁定到与当前Flutter稳定版(3.19.6)匹配的版本,避免自动更新引入的兼容冲突。

  2. 检查Web端Firebase初始化配置
    确认web/index.html中的Firebase JS SDK配置是否正确完整,尝试重新生成Web端Firebase配置代码替换现有内容,确保SDK加载正常。

  3. 禁用FlutterFire调试逻辑
    报错来自_testException方法,可能是调试模式下的错误测试逻辑触发了类型转换问题。尝试通过以下命令启动应用,禁用FlutterFire调试:

    flutter run -d chrome --dart-define=FLUTTERFIRE_DEBUG=false
    

    或在Firebase初始化时添加debugEnabled: false参数(若适用)。

  4. 降级Flutter版本
    若上述方法无效,尝试降级到之前能正常运行的Flutter版本,确认是否是Flutter 3.19.6引入的Web端兼容性问题。

  5. 排查自定义错误处理逻辑
    全局搜索代码中是否有手动将ArgumentError转换为JS对象的逻辑,或第三方包在Web端处理错误时存在类型不兼容的情况。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 21:43:14