Failing to build for web
Closed this issue · 4 comments
The Issue
My app is failling to build to web with dart2js issues.
I get the following messages:
Build Output
Build Output
Target dart2js failed: Exception:
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:106:6:
Error: Expected a class member, but got ')'.
});
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:106:7:
Error: Expected a class member, but got ';'.
});
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:5:
Error: A method declaration needs an explicit list of parameters.
innerWebSocket.onMessage.listen((event) {
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:29:
Error: Expected '{' before this.
innerWebSocket.onMessage.listen((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:5:
Error: The name of a constructor must match the name of the enclosing class.
innerWebSocket.onMessage.listen((event) {
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:29:
Error: Expected a class member, but got '.'.
innerWebSocket.onMessage.listen((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:37:
Error: Expected an identifier, but got '('.
innerWebSocket.onMessage.listen((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:45:
Error: Expected ')' before this.
innerWebSocket.onMessage.listen((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:5:
Error: A method declaration needs an explicit list of parameters.
innerWebSocket.onClose.first.then((event) {
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:27:
Error: Expected '{' before this.
innerWebSocket.onClose.first.then((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:5:
Error: The name of a constructor must match the name of the enclosing class.
innerWebSocket.onClose.first.then((event) {
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:27:
Error: Expected a class member, but got '.'.
innerWebSocket.onClose.first.then((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:39:
Error: Expected an identifier, but got '('.
innerWebSocket.onClose.first.then((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:47:
Error: Expected ')' before this.
innerWebSocket.onClose.first.then((event) {
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:28:
Error: The name of a constructor must match the name of the enclosing class.
innerWebSocket.onClose.first.then((event) {
^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:138:1:
Error: Expected a declaration, but got '}'.
}
^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:16:7:
Error: The non-abstract class 'HtmlWebSocketChannel' is missing implementations for these members:
- HtmlWebSocketChannel.listen
class HtmlWebSocketChannel extends StreamChannelMixin
^^^^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:30:
Info: 'HtmlWebSocketChannel.listen' is defined here.
innerWebSocket.onMessage.listen((event) {
^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:125:5:
Error: Undefined name '_controller'.
_controller.local.stream.listen(innerWebSocket.send, onDone: () {
^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:125:37:
Error: Undefined name 'innerWebSocket'.
_controller.local.stream.listen(innerWebSocket.send, onDone: () {
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:129:11:
Error: Undefined name '_localCloseCode'.
if (_localCloseCode != null && _localCloseReason != null) {
^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:129:38:
Error: Undefined name '_localCloseReason'.
if (_localCloseCode != null && _localCloseReason != null) {
^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:130:30:
Error: Undefined name '_localCloseCode'.
innerWebSocket.close(_localCloseCode, _localCloseReason);
^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:130:47:
Error: Undefined name '_localCloseReason'.
innerWebSocket.close(_localCloseCode, _localCloseReason);
^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:130:9:
Error: Undefined name 'innerWebSocket'.
innerWebSocket.close(_localCloseCode, _localCloseReason);
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:131:18:
Error: Undefined name '_localCloseCode'.
} else if (_localCloseCode != null) {
^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:132:30:
Error: Undefined name '_localCloseCode'.
innerWebSocket.close(_localCloseCode);
^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:132:9:
Error: Undefined name 'innerWebSocket'.
innerWebSocket.close(_localCloseCode);
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:134:9:
Error: Undefined name 'innerWebSocket'.
innerWebSocket.close();
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:108:5:
Error: Final field 'innerWebSocket' is not initialized by this constructor.
innerWebSocket.onMessage.listen((event) {
^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:19:19:
Info: 'innerWebSocket' is defined here.
final WebSocket innerWebSocket;
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:5:
Error: Final field 'innerWebSocket' is not initialized by this constructor.
innerWebSocket.onClose.first.then((event) {
^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:19:19:
Info: 'innerWebSocket' is defined here.
final WebSocket innerWebSocket;
^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:116:28:
Error: Final field 'innerWebSocket' is not initialized by this constructor.
innerWebSocket.onClose.first.then((event) {
^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:19:19:
Info: 'innerWebSocket' is defined here.
final WebSocket innerWebSocket;
^^^^^^^^^^^^^^
Error: Compilation failed.
#0 Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:212:7)
#1 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:847:9)
#2 Future.wait. (dart:async/future.dart:525:21)
#3 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:785:32)
#4 Future.wait. (dart:async/future.dart:525:21)
#5 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:785:32)
#6 FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:614:16)
#7 WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:81:34)
#8 BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:191:5)
#9 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1336:27)
#10 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19)
#11 CommandRunner.runCommand (package:args/command_runner.dart:212:13)
#12 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:296:9)
#13 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19)
#14 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:244:5)
#15 run.. (package:flutter_tools/runner.dart:91:9)
#16 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19)
#17 main (package:flutter_tools/executable.dart:91:3)
Compiling lib/main_development.dart for the Web... 13.4s
Exception: Failed to compile application for the Web.
Flutter Doctor
I am running dart 3.0.0, flutter 3.10.0 and my flutter doctor is the following
Flutter Doctor Output
[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.19045.3086], locale en-GB)
• Flutter version 3.10.0 on channel stable at C:\src\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 84a1e904f4 (6 weeks ago), 2023-05-09 07:41:44 -0700
• Engine revision d44b5a94c9
• Dart version 3.0.0
• DevTools version 2.23.1
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at C:\Users\olive\AppData\Local\Android\Sdk
• Platform android-33, build-tools 33.0.2
• ANDROID_HOME = C:\Users\olive\AppData\Local\Android\Sdk
• ANDROID_SDK_ROOT = C:\Users\olive\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
X Android license status unknown.
Run flutter doctor --android-licenses
to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.24)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.11.33328.57
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2022.2)
• Android Studio at C:\Program Files\Android\Android Studio
• 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.6+0-b2043.56-9586694)
[√] VS Code (version 1.79.1)
• VS Code at C:\Users\olive\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.66.0
[√] Connected device (4 available)
• sdk gphone x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version
10.0.19045.3086]
• Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.134
• Edge (web) • edge • web-javascript • Microsoft Edge 114.0.1823.51
[√] Network resources
• All expected network resources are available.
PubSpec
name: rwg_client
description: A Very Good Project created by Very Good CLI.
version: 1.0.0+1
publish_to: none
environment:
sdk: ">=3.0.0 <4.0.0"
dependencies:
bloc: ^8.1.2
equatable: ^2.0.5
fake_game_repository:
path: packages/fake_game_repository
fake_queue_repository:
path: packages/fake_queue_repository
flutter:
sdk: flutter
flutter_bloc: ^8.1.3
flutter_joystick: ^0.0.3
flutter_localizations:
sdk: flutter
flutter_webrtc: ^0.9.34
game_repository:
path: packages/game_repository
http: ^0.13.4
intl: ^0.18.0
janus_client: ^2.2.14
queue_repository:
path: packages/queue_repository
dev_dependencies:
bloc_test: ^9.1.2
flutter_test:
sdk: flutter
mocktail: ^0.3.0
very_good_analysis: ^5.0.0
flutter:
uses-material-design: true
generate: true
The app builds fine for android, but is showing this issue when building for web, I have had a look at the web_socket_channel
and it says that it is dart 3 compatible, so I am unsure what the issue may be. I am happy to provide more details if required.
Try building again followed by flutter clean
On a different machine right now, running dart 3.0.5 and seems to have built fine! Will try flutter clean
when I am back at the same machine. Thank you in advance!
Running flutter clean and building doesn't seem to fix the issue, I have also bumped my windows machine (the failing machine) to dart 3.0.5 and still have the same issues. 🤔
Deleting ../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.0 and rebuilding seemed to fix the issue, guessing it was a stale cache issue? I think flutter pub cache clean
might do this for you.