Getting error : "Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead "

Getting error : "Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead "

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

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 工具 missing.since 我正在为 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.

我通过 myself.Here 修复了这个错误:

我发现 pubspec.yaml 文件中有几个未使用的依赖项 currently.I 导航到我的 .dart_tool\flutter_build\cb8031cdd1bfbcb95122aae4ad9a63d5\web_plugin_registrant.dart 并发现这些依赖项在 registerPlugins() 中被引用.

我清除了 registerPlugins() 中显示的所有那些未使用的依赖项并执行了以下步骤:

1.flutter pub get 2.flutter clean 3.flutter build web

还有中提琴!错误消失了,我在 build\web 文件夹中找到了我的文件。