我正在使用 Docker 在容器中运行 Web 版本的 Flutter。我已经能够让这个工作了;但是,一旦我导入 http 包(
import 'package:http/http.dart')
文件中的 main.dart
),flutter build web
命令就会失败,并出现以下大量错误:
(一些
The type 'JSObject' can't be used as supertype
错误已被删除,但还有更多)
4.819 Compiling lib/main.dart for the Web...
17.16 Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/accelerometer.dart:52:45:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class AccelerometerReadingValues implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/ambient_light.dart:22:44:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class AmbientLightReadingValues implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/anchors.dart:11:27:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class XRAnchor implements JSObject {}
17.16 ^
...
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/webxrlayers.dart:152:40:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class XRProjectionLayerInit implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/webxrlayers.dart:178:30:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class XRLayerInit implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/webxrlayers.dart:305:33:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class XRWebGLBinding implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/webxrlayers.dart:338:35:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class XRMediaLayerInit implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/webxrlayers.dart:426:33:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class XRMediaBinding implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/xhr.dart:92:27:
17.16 Error: The type 'JSObject' can't be used as supertype.
17.16 class FormData implements JSObject {
17.16 ^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:615:9:
17.16 Error: The method 'typeofEquals' isn't defined for the class 'EventTarget'.
17.16 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('/root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
17.16 if (e.typeofEquals('undefined')) {
17.16 ^^^^^^^^^^^^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:617:16:
17.16 Error: The method 'hasProperty' isn't defined for the class 'EventTarget'.
17.16 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('/root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
17.16 } else if (e.hasProperty('mozHidden'.toJS).toDart) {
17.16 ^^^^^^^^^^^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:619:16:
17.16 Error: The method 'hasProperty' isn't defined for the class 'EventTarget'.
17.16 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('/root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
17.16 } else if (e.hasProperty('msHidden'.toJS).toDart) {
17.16 ^^^^^^^^^^^
17.16 /root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/helpers/events/providers.dart:621:16:
17.16 Error: The method 'hasProperty' isn't defined for the class 'EventTarget'.
17.16 - 'EventTarget' is from 'package:web/src/dom/dom.dart' ('/root/.pub-cache/hosted/pub.dev/web-0.3.0/lib/src/dom/dom.dart').
17.16 } else if (e.hasProperty('webkitHidden'.toJS).toDart) {
17.16 ^^^^^^^^^^^
17.16 Error: Compilation failed.
17.16 Command: /usr/local/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /usr/local/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot --platform-binaries=/usr/local/flutter/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true -DF
LUTTER_WEB_AUTO_DETECT=true -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/ade9f18fa00883339efb5386db061e4514527868/ --native-null-assertions --no-source-maps -o /app/.dart_tool/flutter_build/d3b236f988639428bec169f5d50f9c08/app.dill --packages=.dart_tool
/package_config.json --cfe-only /app/.dart_tool/flutter_build/d3b236f988639428bec169f5d50f9c08/main.dart
17.16 #0 RunResult.throwException (package:flutter_tools/src/base/process.dart:127:5)
17.16 #1 _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:326:19)
17.16 <asynchronous suspension>
17.16 #2 Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:188:5)
17.16 <asynchronous suspension>
17.16 #3 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:861:9)
17.16 <asynchronous suspension>
17.16 #4 Future.wait.<anonymous closure> (dart:async/future.dart:518:21)
17.16 <asynchronous suspension>
17.16 #5 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:799:32)
17.16 <asynchronous suspension>
17.16 #6 Future.wait.<anonymous closure> (dart:async/future.dart:518:21)
17.16 <asynchronous suspension>
17.16 #7 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:799:32)
17.16 <asynchronous suspension>
17.16 #8 FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:628:16)
17.16 <asynchronous suspension>
17.16 #9 WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:93:34)
17.16 <asynchronous suspension>
17.16 #10 BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:200:5)
17.16 <asynchronous suspension>
17.16 #11 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1389:27)
17.16 <asynchronous suspension>
17.16 #12 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
17.16 <asynchronous suspension>
17.16 #13 CommandRunner.runCommand (package:args/command_runner.dart:212:13)
17.16 <asynchronous suspension>
17.16 #14 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:355:9)
17.16 <asynchronous suspension>
17.16 #15 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
17.16 <asynchronous suspension>
17.16 #16 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:295:5)
17.16 <asynchronous suspension>
17.16 #17 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:119:9)
17.16 <asynchronous suspension>
17.16 #18 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
17.16 <asynchronous suspension>
17.16 #19 main (package:flutter_tools/executable.dart:90:3)
17.16 <asynchronous suspension>
17.16
17.16 Compiling lib/main.dart for the Web... 12.3s
17.18 Error: Failed to compile application for the Web.
------
failed to solve: process "/bin/sh -c flutter build web" did not complete successfully: exit code: 1
我确保我使用的 Dart 版本与 http 包的版本兼容:
http:1.1.2
Dart:Dart 3.4.0(内部版本 3.4.0-24.0.dev)
颤振:颤振3.19.0-5.0.pre.41
如果你在主分支上,你可以预料到事情会被破坏。如果您实际上不想调试 flutter 本身,请将其恢复到稳定版,或者至少是 beta 版。