如何在构建 Flutter Web 应用程序时解决 "Target dart2js failed" 和 FlutterFire/Firestore 依赖项错误



在Flutter web应用程序中运行flutter build web时,我遇到了一系列无法找到解决方案的错误。

这是一个Flutter网络应用程序。我没有使用Android或iOS或其他任何东西。截至上周五(2022年8月12日(,该建筑状况良好。

在终端中运行flutter build web时,我得到以下错误:

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.

这些错误让我认为JavaScript是如何生成的,和/或是否在没有零安全的情况下构建存在问题。

Flutter修复程序今天合并了Flutter/issues/109160,旨在修复generated_plugin_registrant.dart的一个问题,但它被降级到主通道和测试通道。我在稳定频道。

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

在repo中的每个文件的顶部,我都有// @dart=2.9,这样在我被迁移之前,构建不应该使用空安全性。

我试过:

  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

我读过&尝试使用:

  1. flutter/issues/109160,但这似乎不相关,因为我在稳定通道上
  2. S。O.getting-error-target-dart2js
  3. 无法编译我的flutter网页
  4. flutter build web构建没有健全的零安全并在错误时运行

我还创建了一个test_web_app,导入了Firebase/FlutterFire库,构建得很好,尽管无可否认,我实际上并没有在测试应用程序中使用它们中的任何一个。我只是将它们添加到pubspec和index.html中,看看这是否对构建有任何影响。

感谢您的指导&想想看!!!

我通过以下操作解决了构建问题:

  1. 运行flutter pub outdated

输出:

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. 手动将pubspec.yaml更新为";最新的";为cloud_firestorefirebase_corefirebase_authcloud_functions中的每一个列出的版本。

  2. VS Code自动为我运行flutter pub get

  3. flutter build web测试

;"玛丽万岁";,但它起了作用。我不明白为什么一周内会出现问题,但如果有人有任何见解,我很想了解他们!!!

最新更新