执行build_runner命令报错:ClassDeclaration无macroKeyword getter
build_runner构建失败:macroKeyword未定义错误
错误详情
执行build_runner命令时出现以下构建错误:
Failed to build build_runner:build_runner: ../../.pub-cache/hosted/pub.dev/dart_style-2.3.5/lib/src/front_end/ast_node_visitor.dart:251:16: Error: The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'. - 'ClassDeclaration' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../.pub-cache/hosted/pub.dev/analyzer-6.2.0/lib/src/dart/ast/ast.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'macroKeyword'. node.macroKeyword, ^^^^^^^^^^^^ ../../.pub-cache/hosted/pub.dev/dart_style-2.3.5/lib/src/source_visitor.dart:595:19: Error: The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'. - 'ClassDeclaration' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../.pub-cache/hosted/pub.dev/analyzer-6.2.0/lib/src/dart/ast/ast.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'macroKeyword'. modifier(node.macroKeyword); ^^^^^^^^^^^^
问题原因
dart_style 2.3.5版本与analyzer 6.2.0版本不兼容:dart_style代码中引用了ClassDeclaration类的macroKeyword属性,但analyzer 6.x版本已经移除了该属性,导致构建时找不到对应 getter。
解决步骤
- 更新dart_style到兼容版本:在项目的
pubspec.yaml中指定dart_style的版本至少为2.3.6(该版本修复了与analyzer 6.x的兼容问题),示例:dev_dependencies: dart_style: ^2.3.6 - 清理缓存并重新拉取依赖:
dart pub cache clean dart pub get - 重新运行build_runner:
dart run build_runner build
内容的提问来源于stack exchange,提问作者Code Hunter
相关产品推荐
相关产品推荐

