Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter http package causing failed build for 'flutter build web'

I am using Docker to run a web version of Flutter in a container. I have been able to get this working; however, once I import the http package (import 'package:http/http.dart') in my main.dart file, the flutter build web command fails with the following large list of errors:

(some of the The type 'JSObject' can't be used as supertype errors were removed, but there are many more)

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

I ensured that I am using a compatible Dart version with the version of the http package:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

http: 1.1.2

Dart: Dart 3.4.0 (build 3.4.0-24.0.dev)

Flutter: Flutter 3.19.0-5.0.pre.41

>Solution :

If you’re on master branch, you can expect things to be broken. If you actually don’t want to be debugging flutter itself, dial it back to stable, or at least beta.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading