flutter pub run build_runner build 已弃用

Mah*_*our 9 dart flutter built-value build-runner

当我运行时flutter pub run build_runner build --delete-conflicting-outputs,我收到此错误:

Deprecated. Use `dart run` instead.
[INFO] Generating build script completed, took 169ms
[WARNING] ../../../.pub-cache/hosted/pub.dev/built_value_generator-8.6.1/lib/src/dart_types.dart:65:21: Error: 'InvalidType' isn't a type.
    if (dartType is InvalidType) {
                    ^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/built_value_generator-8.6.1/lib/src/value_source_class.dart:497:20: Error: The getter 'name2' isn't defined for the class 'NamedType'.
 - 'NamedType' is from 'package:analyzer/dart/ast/ast.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-5.7.1/lib/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'name2'.
          if (type.name2.lexeme == 'Built') {
                   ^^^^^
[INFO] Precompiling build script... completed, took 547ms
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
Run Code Online (Sandbox Code Playgroud)

所以我dart run build_runner build --delete-conflicting-outputs改为运行并收到此错误:

[INFO] Generating build script completed, took 172ms
[WARNING] ../../../.pub-cache/hosted/pub.dev/built_value_generator-8.6.1/lib/src/dart_types.dart:65:21: Error: 'InvalidType' isn't a type.
    if (dartType is InvalidType) {
                    ^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/built_value_generator-8.6.1/lib/src/value_source_class.dart:497:20: Error: The getter 'name2' isn't defined for the class 'NamedType'.
 - 'NamedType' is from 'package:analyzer/dart/ast/ast.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-5.7.1/lib/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'name2'.
          if (type.name2.lexeme == 'Built') {
                   ^^^^^
[INFO] Precompiling build script... completed, took 570ms
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
Run Code Online (Sandbox Code Playgroud)

我尝试添加gql: 0.13.0到 dependency_overrides 但我再次遇到同样的错误!

我正在使用Flutter (Channel stable, 3.10.5, on macOS 13.2.1 22D68 darwin-arm64, locale en-US)build_runner: ^2.4.5

我如何解决它?

Son*_*hai 12

您可以尝试通过修改升级build_runner到最新版本(目前是2.4.7)pubsec.yaml

dev_dependencies:
...
build_runner: ^2.4.7
...
Run Code Online (Sandbox Code Playgroud)

或者

flutter pub upgrade build_runner
Run Code Online (Sandbox Code Playgroud)

并且您还应该使用以下命令清除所有颤振缓存

flutter clean
Run Code Online (Sandbox Code Playgroud)

如果它不能解决你的问题,你会尝试

dart run build_runner doctor
Run Code Online (Sandbox Code Playgroud)

获取有关此错误的更多信息。