flutter pub run build_runner 构建已弃用

问题描述 投票:0回答:2

当我运行

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.

所以我运行

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.

我尝试将

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

如何解决?

flutter dart build-runner built-value
2个回答
10
投票

您可以尝试通过修改

build_runner
来升级
pubsec.yaml

到最新版本(目前是2.4.7)
dev_dependencies:
...
build_runner: ^2.4.7
...

flutter pub upgrade build_runner

您还应该使用

清理所有颤振缓存
flutter clean

如果没有解决你的问题,你会尝试

dart run build_runner doctor

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


1
投票

删除第一个 pubspec.lock 文件。

然后扑干净 扑扑 pubget

所以它会生成network.g.dart和pubspec.lock文件

flutter pub run build_runner 构建

© www.soinside.com 2019 - 2024. All rights reserved.