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

Flutter 3.22版本Web端Chrome构建失败及报错求助

Flutter 3.22 Web构建失败问题解决

问题现象

升级至Flutter 3.22版本后,Web端项目无法在Chrome浏览器完成构建,出现多起依赖web包的报错。已执行flutter clean和flutter pub get命令,问题未解决。

报错详情

class XRMediaBinding implements JSObject {
                                ^
../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/xhr.dart:92:27: Error: The type 'JSObject' can't be used as supertype.
class FormData implements JSObject {
                          ^
../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:615:9: Error: The method 'typeofEquals' isn't defined for the class 'EventTarget'.
 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
Try correcting the name to the name of an existing method, or defining a method named 'typeofEquals'.
  if (e.typeofEquals('undefined')) {
        ^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:617:16: Error: The method 'hasProperty' isn't defined for the class 'EventTarget'.
 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hasProperty'.
  } else if (e.hasProperty('mozHidden'.toJS).toDart) {
               ^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:619:16: Error: The method 'hasProperty' isn't defined for the class 'EventTarget'.
 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hasProperty'.
  } else if (e.hasProperty('msHidden'.toJS).toDart) {
               ^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:621:16: Error: The method 'hasProperty' isn't defined for the class 'EventTarget'.
 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hasProperty'.
  } else if (e.hasProperty('webkitHidden'.toJS).toDart) {
               ^^^^^^^^^^^
Failed to compile application.

解决步骤

  • 检查pubspec.yaml,若直接依赖了web包,将版本升级至与Flutter 3.22兼容的版本(如^0.4.0及以上)
  • 若未直接依赖web包,执行以下命令更新依赖并清理缓存:
    1. flutter pub cache clean
    2. flutter pub upgrade
    3. flutter pub get
  • 若上述方法无效,可在pubspec.yaml中强制指定web包版本:
    dependencies:
      web: ^0.4.0
    

内容的提问来源于stack exchange,提问作者Eren Malkoç

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 03:59:58