【问题标题】:Getting error : "Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead "出现错误:“目标 dart2js 失败:异常:警告:不推荐使用 'dart2js' 入口点脚本,请改用 'dart compile js'”
【发布时间】:2022-07-26 22:56:04
【问题描述】:

我正在尝试使用flutter build 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.

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我自己修复了这个错误。这就是我所做的:

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

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

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

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

    【讨论】:

    • 我今天在将项目从英特尔笔记本电脑转移到 m1 后遇到了同样的问题。我只需要做flutter clean;然后构建工作。
    • 所以仅仅运行“flutter clean”就可以让你运行flutter build web没有错误?我试过了,它对我不起作用。
    【解决方案2】:

    flutter build web 在我的本地工作但不在我的服务器上,在sudo reboot 之后它再次工作。上面的 sugestet 答案对我不起作用...

    【讨论】:

      猜你喜欢
      • 2014-01-21
      • 2014-09-03
      • 2014-10-10
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 2021-08-09
      • 2014-01-10
      相关资源
      最近更新 更多