skillit zimberg
skillit zimberg

Reputation: 1133

How to resolve "Target dart2js failed" and FlutterFire/Firestore dependency errors when building Flutter web app

When running flutter build web in my Flutter web app, I am getting a series of errors that I haven't been able to find solutions for.

This is a Flutter web app. I'm not using Android or iOS or anything else. It was building fine as of last Friday (August 12, 2022).

Running flutter build web in the terminal I get the following errors:

Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-2.6.18/lib/cloud_firestore_web.dart:101:14:
Error: The method 'FirebaseFirestoreWeb.runTransaction' has fewer named arguments than those of overridden method
'FirebaseFirestorePlatform.runTransaction'.
  Future<T?> runTransaction<T>(TransactionHandler<T> transactionHandler,
             ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_platform_interface-5.7.2/lib/src/platform_interface/platform_in
terface_firestore.dart:168:14:
Info: This is the overridden method ('runTransaction').
  Future<T?> runTransaction<T>(TransactionHandler<T> transactionHandler,
             ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-2.6.18/lib/cloud_firestore_web.dart:101:14:
Error: The method 'FirebaseFirestoreWeb.runTransaction' doesn't have the named parameter 'maxAttempts' of overridden method
'FirebaseFirestorePlatform.runTransaction'.
  Future<T?> runTransaction<T>(TransactionHandler<T> transactionHandler,
             ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_platform_interface-5.7.2/lib/src/platform_interface/platform_in
terface_firestore.dart:168:14:
Info: This is the overridden method ('runTransaction').
  Future<T?> runTransaction<T>(TransactionHandler<T> transactionHandler,
             ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.18/lib/firebase_auth_web.dart:102:24:
Error: The method 'FirebaseAuthWeb.delegateFor' has fewer named arguments than those of overridden method
'FirebaseAuthPlatform.delegateFor'.
  FirebaseAuthPlatform delegateFor({required FirebaseApp app}) {
                       ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.5.4/lib/src/platform_interface/platform_inte
rface_firebase_auth.dart:87:24:
Info: This is the overridden method ('delegateFor').
  FirebaseAuthPlatform delegateFor(
                       ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.18/lib/firebase_auth_web.dart:402:16:
Error: The method 'FirebaseAuthWeb.verifyPhoneNumber' has fewer named arguments than those of overridden method
'FirebaseAuthPlatform.verifyPhoneNumber'.
  Future<void> verifyPhoneNumber({
               ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.5.4/lib/src/platform_interface/platform_inte
rface_firebase_auth.dart:645:16:
Info: This is the overridden method ('verifyPhoneNumber').
  Future<void> verifyPhoneNumber({
               ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.18/lib/firebase_auth_web.dart:402:16:
Error: The method 'FirebaseAuthWeb.verifyPhoneNumber' doesn't have the named parameter 'multiFactorInfo' of overridden method
'FirebaseAuthPlatform.verifyPhoneNumber'.
  Future<void> verifyPhoneNumber({
               ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.5.4/lib/src/platform_interface/platform_inte
rface_firebase_auth.dart:645:16:
Info: This is the overridden method ('verifyPhoneNumber').
  Future<void> verifyPhoneNumber({
               ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.18/lib/src/firebase_auth_web_recaptcha_verifier_factory.d
art:93:36:
Error: The method 'RecaptchaVerifierFactoryWeb.delegateFor' has fewer named arguments than those of overridden method
'RecaptchaVerifierFactoryPlatform.delegateFor'.
  RecaptchaVerifierFactoryPlatform delegateFor({
                                   ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.5.4/lib/src/platform_interface/platform_inte
rface_recaptcha_verifier_factory.dart:82:36:
Info: This is the overridden method ('delegateFor').
  RecaptchaVerifierFactoryPlatform delegateFor({
                                   ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.18/lib/src/firebase_auth_web_recaptcha_verifier_factory.d
art:93:36:
Error: The method 'RecaptchaVerifierFactoryWeb.delegateFor' doesn't have the named parameter 'auth' of overridden method
'RecaptchaVerifierFactoryPlatform.delegateFor'.
  RecaptchaVerifierFactoryPlatform delegateFor({
                                   ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.5.4/lib/src/platform_interface/platform_inte
rface_recaptcha_verifier_factory.dart:82:36:
Info: This is the overridden method ('delegateFor').
  RecaptchaVerifierFactoryPlatform delegateFor({
                                   ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.4.0/lib/src/recaptcha_verifier.dart:57:27:
Error: Required named parameter 'auth' must be provided.
      _factory.delegateFor(
                          ^
../../../../Flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.18/lib/src/firebase_auth_web_user.dart:23:14:
Error: Too few positional arguments: 3 required, 2 given.
      : super(auth, {
             ^
Error: Compilation failed.


Compiling lib/main.dart for the Web...                             15.7s
Exception: Failed to compile application for the Web.

These errors lead me to think that there is a problem with how JavaScript is being generated and/or whether or not building without null safety is happening at all.

The Flutter fix merged today flutter/issues/109160 was meant to fix an issue with generated_plugin_registrant.dart, but that is relegated to the master and beta channels. I'm on the stable channel.

flutter doctor -v:

[✓] Flutter (Channel stable, 3.0.5, on Mac OS X 10.15.7 19H2026 darwin-x64, locale en-US)
    • Flutter version 3.0.5 at /Users/foreignfood/Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (5 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/foreignfood/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 12.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ✗ Flutter requires Xcode 13 or higher.
      Download the latest version or update via the Mac App Store.
    ! CocoaPods 1.10.2 out of date (1.11.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart
        side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.46.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • Mac OS X 10.15.7 19H2026 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 104.0.5112.101

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

pubspec.yaml:

name: web_flutter
description: An app built using Flutter for web

environment:
  sdk: ">=2.3.0-dev.0.1 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  provider: any
  rxdart: ^0.27.5
  http: ^0.13.0
  json_annotation: ^4.6.0
  intl: any
  firebase: any
  uuid: any
  algolia: ^1.0.1
  flutter_typeahead: ^4.0.0
  timeago: ^3.3.0
  datetime_picker_formfield: ^2.0.0
  firebase_core: ^1.4.0
  firebase_auth: ^3.0.1
  cloud_firestore: ^3.2.0
  cloud_functions: "^3.0.0"
  multi_select_flutter: ^4.1.2
  date_time_picker: ^2.1.0

dev_dependencies:
  build_runner: ^2.2.0
  build_web_compilers: ^3.2.5
  pedantic: ^1.8.0+1
  json_serializable: ^6.3.1
  universal_html: any
  test: any

flutter:
  uses-material-design: true

At the top of each file in the repo I have // @dart=2.9 in place so that builds should not use null safety until I get migrated.

I have tried:

  1. flutter pub get -> flutter clean -> flutter build web
  2. flutter pub upgrade -> flutter pub outdated -> flutter pub upgrade --major-versions -> flutter clean -> flutter build web --no-sound-null-safety

I have read & tried working with:

  1. flutter/issues/109160, but this doesn't seem relevant because I'm on the stable channel.
  2. S.O. getting-error-target-dart2js
  3. cant-compile-my-flutter-web
  4. flutter-build-web-builds-without-sound-null-safety-and-runs-on-error

I also created a test_web_app, importing the Firebase/FlutterFire libraries and that is building fine, though admittedly I'm not actually using any of them in that test app. I just added them to the pubspec and index.html to see if that had any effect on building.

Thank you for any guidance & thoughts on this!!!

Upvotes: 2

Views: 1383

Answers (1)

skillit zimberg
skillit zimberg

Reputation: 1133

I fixed the build problem by doing the following:

  1. Run flutter pub outdated:

OUTPUT:

Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name                      Current  Upgradable  Resolvable  Latest  

direct dependencies:             
cloud_firestore                   *3.2.0   *3.2.0      *3.2.0      3.4.5   
cloud_functions                   *3.3.0   *3.3.0      *3.3.0      3.3.5   
firebase_auth                     *3.4.0   *3.4.0      *3.4.0      3.6.4   
firebase_core                     *1.19.0  *1.19.0     *1.19.0     1.21.0  

dev_dependencies: all up-to-date.

transitive dependencies:         
characters                        *1.2.0   *1.2.0      *1.2.0      1.2.1   
cloud_firestore_web               *2.6.18  *2.6.18     *2.6.18     2.8.5   
cloud_functions_web               *4.2.17  *4.2.17     *4.2.17     4.3.3   
firebase_auth_web                 *3.3.18  *3.3.18     *3.3.18     4.2.4   
firebase_core_platform_interface  *4.4.1   *4.4.1      *4.4.1      4.5.0   
firebase_core_web                 *1.6.5   *1.6.5      *1.6.5      1.7.1   
material_color_utilities          *0.1.4   *0.1.4      *0.1.4      0.2.0   
meta                              *1.7.0   *1.7.0      *1.7.0      1.8.0   
vector_math                       *2.1.2   *2.1.2      *2.1.2      2.1.3   

transitive dev_dependencies:     
frontend_server_client            *2.1.3   *2.1.3      *2.1.3      3.0.0   
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.
  1. Manually update pubspec.yaml to the "Latest" versions listed for each of cloud_firestore,firebase_core, firebase_auth, and cloud_functions.

  2. VS Code automatically ran flutter pub get for me.

  3. Tested with flutter build web

This was a total "Hail, Mary", but it worked. I don't understand why there would be a problem over the course of a week, but if anybody has any insights, I would love to know them!!!

Upvotes: 2

Related Questions