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包,执行以下命令更新依赖并清理缓存:flutter pub cache cleanflutter pub upgradeflutter pub get
- 若上述方法无效,可在
pubspec.yaml中强制指定web包版本:dependencies: web: ^0.4.0
内容的提问来源于stack exchange,提问作者Eren Malkoç
相关产品推荐
相关产品推荐

