开发者问题收集

出现错误:“目标 dart2js 失败:异常:警告:'dart2js' 入口点脚本已被弃用,请改用'dart compile js'”

2022-05-27
16742

我尝试使用 flutter build web 在发布模式下构建 Flutter Web 应用程序(也尝试过 flutter build web --no-sound-null-safety )。当我这样做时,我收到以下错误。

D:\saves\reset_password>flutter build web

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
.dart_tool/flutter_build/1916f9367c0e6ad6c929bd88cf5227e5/web_plugin_registrant.dart:14:38:
Error: Null safety features are disabled for this library.
void registerPlugins([final Registrar? pluginRegistrar]) {
                                     ^
Error: Compilation failed.


Compiling lib\main.dart for the Web...                             44.9s
Exception: Failed to compile application for the Web.

当我使用 flutter run 在调试模式下直接运行它时,它工作正常。 注意:我最近升级到 Flutter 3.0 并且我正在使用 Android Studio。 下面是我的 flutter doctor (我知道缺少 android 工具。因为我是为 Web 构建的,所以我没有太注意它)

D:\saves\reset_password>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 3.1.0-0.0.pre.966, on Microsoft Windows [Version 10.0.19044.1706], locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    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
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
[√] Android Studio (version 4.1)
[√] VS Code (version 1.66.2)
[√] Connected device (3 available)
[√] HTTP Host Availability

! Doctor found issues in 1 category.
3个回答

对我来说,解决方案是在 cmd/terminal 上启动 flutter clean && flutter pub get

Nimr Sawafta
2022-09-08

删除 /flutter/bin/cache 文件夹。

运行 flutter doctor

然后,运行 flutter cleanflutter pub getflutter build web

Jeiel Junio
2023-01-14

我遇到了类似的问题。 这是在基于 Ubuntu 的服务器上。

就我而言,我遇到了:

目标 dart2js 失败:异常:警告: “dart2js”入口点脚本已弃用,请改用“dart compile js”。 flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.19/lib/firebase_auth_web.dart:402:16: 错误:方法“FirebaseAuthWeb.verifyPhoneNumber”的命名参数比重写方法“FirebaseAuthPlatform.verifyPhoneNumber”的命名参数少。 ...

我发现 firebase_auth_web 依赖项有一个弃用的版本,并且未在项目中使用。因此我删除了这个依赖项。之后问题就消失了。

Maksim Ryabovol
2022-07-27