【问题标题】:Flutter Build For Web - "Failed to compile application"Flutter Build For Web - “无法编译应用程序”
【发布时间】:2020-07-09 16:50:05
【问题描述】:

我为我的项目启用了 Web 支持,在运行 flutter run -d chrome 后出现以下错误:

Launching lib/main.dart on Chrome in debug mode...
Syncing files to device Chrome...                                                                                                                                                                    
Compiler message:                                  
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:26:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  GoogleAuth.fakeConstructor$();                                                                                   
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:216:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  SigninOptionsBuilder.fakeConstructor$();                                                                         
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:351:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequestPromise.fakeConstructor$();                                                                           
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:378:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequest.fakeConstructor$() : super.fakeConstructor$();                                                       
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:402:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpBatch.fakeConstructor$();                                                                                    
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:440:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  RpcRequest.fakeConstructor$();                                                                                   
  ^                                                                                                                
Syncing files to device Chrome...                               19,442ms (!)                                       
Failed to compile application.
Tals-Macbook:matkonit talbarda$ flutter run -d chrome
Launching lib/main.dart on Chrome in debug mode...
Syncing files to device Chrome...                                                                                                                                                                    
Compiler message:                                  
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:26:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  GoogleAuth.fakeConstructor$();                                                                                   
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:216:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  SigninOptionsBuilder.fakeConstructor$();                                                                         
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:351:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequestPromise.fakeConstructor$();                                                                           
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:378:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequest.fakeConstructor$() : super.fakeConstructor$();                                                       
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:402:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpBatch.fakeConstructor$();                                                                                    
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:440:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  RpcRequest.fakeConstructor$();                                                                                   
  ^                                                                                                                
Syncing files to device Chrome...                               17,899ms (!)                                       
Failed to compile application.

我该如何解决这个问题?

【问题讨论】:

    标签: flutter dart flutter-web


    【解决方案1】:

    我注意到这个问题已在 google_sign_in_web 0.9.0 中得到修复。因此,请更改 pubspec.yaml 文件中的版本。

    google_sign_in_web: ^0.9.1
    

    2020 年 4 月 20 日更新:如果您对 google_sign_in 有依赖关系,请在 pubspec.yaml 文件中更改该版本。

    google_sign_in: 4.4.3
    

    之前: 但是,当您像我一样并且对 google_sign_in 有依赖性时,那么您还有更多需要更改的东西...... 如果您将 google_sign_in_web 更改为 0.9.0 并将 google_sign_in 的版本更改为 4.4.1,则检索包将失败:

    Because ${your_project_name} depends on google_sign_in 4.4.1 which depends on google_sign_in_web ^0.8.2, google_sign_in_web ^0.8.2 is required.
    So, because ${your_project_name} depends on google_sign_in_web ^0.9.0, version solving failed.
    pub get failed (1; So, because  ${your_project_name} depends on google_sign_in_web ^0.9.0, version solving failed.)
    

    在这种情况下,您必须等待 google_sign_in 升级(我创建了拉取请求 https://github.com/flutter/plugins/pull/2647),或者暂时像我一样:

    1) 从https://github.com/flutter/plugins克隆flutter插件

    mkdir /src
    cd /src
    git clone https://github.com/flutter/plugins.git
    

    2) 更改 /src/plugins/plugins/packages/google_sign_in/google_sign_in/pubspec.yaml 中的文件 pubspec.yaml

      google_sign_in_web: ^0.9.0
    

    3) 更改项目中的依赖项以指向更改后的 google_sign_in 版本,即

    google_sign_in:
      path: ../../flutter/plugins/packages/google_sign_in/google_sign_in
    google_sign_in_web: ^0.9.0
    

    【讨论】:

      【解决方案2】:

      改用测试版。

      flutter channel beta
      

      【讨论】:

        【解决方案3】:

        由于某些原因,较新版本的 Flutter 停止支持这种格式的依赖项: folding_cell: "^0.1.2" 相反,请检查您的 pubspec.yaml 并将具有该格式的任何依赖项更改为: folding_cell: ^1.0.0 我以 fold_cell 为例。 这为我解决了问题,希望对某人有所帮助。

        【讨论】:

          【解决方案4】:

          使用 dart pub outdated 来识别过时的包依赖项并获取有关如何更新它们的建议。依赖管理的最佳实践包括使用最新的稳定包版本,这样您就可以获得最新的错误修复和改进。

          打开终端和应用文件夹的路径 并运行 flutter pub outdated 以列出所有过时的包。

          cmd:flutter pub 已过时

          并将所有过时的软件包升级到最新或可解决的版本。 并从终端颤振酒吧升级运行。 将过时的软件包更新到最新的软件包。 然后运行您的应用程序。

          more info:https://dart.dev/tools/pub/cmd/pub-outdated

          【讨论】:

            猜你喜欢
            • 2022-10-17
            • 2021-02-14
            • 2023-02-11
            • 2022-11-18
            • 2022-08-12
            • 2021-11-01
            • 1970-01-01
            • 2022-01-17
            • 2023-03-20
            相关资源
            最近更新 更多