Dart Generators:为什么我得到的类型'LibraryDirectiveImpl'不是'Statement'类型的子类型

时间:2019-09-22 05:14:13

标签: flutter dart dart-pub

在遇到问题之前,我想说的是,这是我第一次尝试在Dart上使用生成器,那就说得更深入些。

好吧,我正在尝试遵循以下示例:https://github.com/dart-lang/source_gen/tree/master/example 顺便说一句,根据我的需要进行更改,我什至不必运行存储库的克隆,遇到与LibraryDirectiveImpl有关的错误,我不知道如何调试它

可能是因为我使用的是flutter pub run build_runner build而不是pub run build_runner build,实际上我想在Flutter项目中运行它。

当我运行build_runner时,我在控制台上遇到了这个问题

You have hit a bug in build_runner
Please file an issue with reproduction steps at https://github.com/dart-lang/build/issues


type 'LibraryDirectiveImpl' is not a subtype of type 'Statement'
package:analyzer/src/summary2/ast_binary_reader.dart 1086:7       AstBinaryReader._read_labeledStatement
package:analyzer/src/summary2/ast_binary_reader.dart 1801:16      AstBinaryReader._readNode
package:analyzer/src/summary2/ast_binary_reader.dart 1914:19      AstBinaryReader._readNodeList
package:analyzer/src/summary2/ast_binary_reader.dart 357:21       AstBinaryReader._read_compilationUnit
package:analyzer/src/summary2/ast_binary_reader.dart 1699:16      AstBinaryReader._readNode
package:analyzer/src/summary2/ast_binary_reader.dart 59:14        AstBinaryReader.readNode
package:analyzer/src/summary2/linked_unit_context.dart 1040:26    LinkedUnitContext._ensureUnitWithDeclarations
package:analyzer/src/summary2/linked_unit_context.dart 91:5       LinkedUnitContext.unit_withDeclarations
package:analyzer/src/summary2/linked_element_factory.dart 307:27  _ElementRequest._createLibraryElement
package:analyzer/src/summary2/linked_element_factory.dart 147:14  _ElementRequest.elementOfReference
package:analyzer/src/summary2/linked_element_factory.dart 72:45   LinkedElementFactory.elementOfReference
package:analyzer/src/summary2/linked_element_factory.dart 104:12  LinkedElementFactory.libraryOfUri
package:analyzer/src/summary2/link.dart 213:34                    Linker._createTypeSystem
package:analyzer/src/summary2/link.dart 98:5                      Linker._buildOutlines
package:analyzer/src/summary2/link.dart 83:5                      Linker.link
package:analyzer/src/summary2/link.dart 35:10                     link
package:analyzer/src/dart/analysis/library_context.dart 318:26    LibraryContext.load2.loadBundle
dart:collection                                                   __CompactLinkedHashSet&_HashFieldBase&_HashBase&_OperatorEqualsAndHashCode&SetMixin.forEach
package:analyzer/src/dart/analysis/library_context.dart 273:32    LibraryContext.load2.loadBundle
package:analyzer/src/dart/analysis/library_context.dart 370:17    LibraryContext.load2.<fn>
package:analyzer/src/dart/analysis/performance_logger.dart 34:15  PerformanceLog.run
package:analyzer/src/dart/analysis/library_context.dart 368:12    LibraryContext.load2
package:analyzer/src/dart/analysis/library_context.dart 95:7      new LibraryContext
package:analyzer/src/dart/analysis/driver.dart 1439:29            AnalysisDriver._createLibraryContext
package:analyzer/src/dart/analysis/driver.dart 1380:28            AnalysisDriver._computeUnitElement.<fn>
package:analyzer/src/dart/analysis/performance_logger.dart 34:15  PerformanceLog.run
package:analyzer/src/dart/analysis/driver.dart 1378:20            AnalysisDriver._computeUnitElement
package:analyzer/src/dart/analysis/driver.dart 997:34             AnalysisDriver.performWork
package:analyzer/src/dart/analysis/driver.dart 1931:24            AnalysisDriverScheduler._run
package:analyzer/src/dart/analysis/driver.dart 1865:5             AnalysisDriverScheduler.start
package:build_resolvers/src/analysis_driver.dart 54:13            analysisDriver
package:build_resolvers/src/resolver.dart 138:18                  new AnalyzerResolvers
package:build_runner_core/src/generate/options.dart 193:19        BuildOptions.create
package:build_runner/src/generate/build.dart 85:36                build
package:build_runner/src/entrypoint/build.dart 28:24              BuildCommand.run
package:args/command_runner.dart 197:27                           CommandRunner.runCommand
package:args/command_runner.dart 112:25                           CommandRunner.run.<fn>
dart:async                                                        new Future.sync
package:args/command_runner.dart 112:14                           CommandRunner.run
package:build_runner/src/entrypoint/run.dart 24:31                run
.dart_tool\build\entrypoint\build.dart 31:22                      main

pub failed (1)

扑扑医生

[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Microsoft Windows [Version 10.0.17763.737], locale en-US)
    • Flutter version 1.7.8+hotfix.4 at C:\Flutter
    • Framework revision 20e59316b8 (9 weeks ago), 2019-07-18 20:04:33 -0700
    • Engine revision fee001c93f
    • Dart version 2.4.0


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at c:\Users\hj_ju\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = c:\Users\hj_ju\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] IntelliJ IDEA Ultimate Edition (version 2019.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[√] VS Code (version 1.38.1)
    • VS Code at C:\Users\hj_ju\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.4.1

[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

1 个答案:

答案 0 :(得分:2)

今天使用documentation时,我得到了相同的错误消息。

最后,我从json_serializable找到了解决方案(downgrade the package 'analyzer' version from 0.38.3 to 0.38.2),它有效。

dependencies:
  //analyzer: ^0.38.2
  analyzer: 0.38.2

祝你好运!