运行 build_runner 时出现未知 riverpod_generator 错误。错误:无法预编译构建脚本 .dart_tool/build/entrypoint/build.dart
我一直在 Flutter 中使用
riverpod_generator
练习 riverpod,一切运行正常。
命令
dart run build_runner watch -d
也运行正常,并生成
.g.dart
文件,但突然出现问题,在运行 build runner 时显示此错误:
user@name MINGW64 /a/flutter_code/aa
$ dart run build_runner build -v
[INFO] Entrypoint:Generating build script...
[INFO] Entrypoint:Generating build script completed, took 663ms
[INFO] Bootstrap:Precompiling build script......
[WARNING] Bootstrap:
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/functional_provider.dart:38:33: Error: The getter
'createdType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
final returnType = provider.createdType;
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/functional_provider.dart:61:48: Error: The getter
'valueType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
final $providerName = $providerType<${provider.valueType}>.internal(
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/functional_provider.dart:69:50: Error: The getter
'valueType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
typedef $refName = ${providerType}Ref<${provider.valueType}>;
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/class_based_provider.dart:101:33: Error: The getter 'createdType' isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
final returnType = provider.createdType;
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/class_based_provider.dart:115:66: Error: The getter 'valueType' isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
final $providerName = $providerType<${provider.name}, ${provider.valueType}>.internal(
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/class_based_provider.dart:123:61: Error: The getter 'valueType' isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
typedef $notifierTypedefName = $notifierBaseType<${provider.valueType}>;
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:55:32: Error: The getter 'createdType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
var createdType = provider.createdType.toString();
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:57:33: Error: The getter 'createdType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
final returnType = provider.createdType;
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:65:44: Error: The getter 'valueType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
createdType = 'FutureOr<${provider.valueType}>';
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:90:38: Error: The getter 'valueType' isn't defined for the class 'FunctionalProviderDeclaration'.
- 'FunctionalProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
providerGenerics: '<${provider.valueType}>',
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:134:33: Error: The getter 'createdType' isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
final returnType = provider.createdType;
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:167:56: Error: The getter 'valueType'
isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
providerGenerics: '<${provider.name}, ${provider.valueType}>',
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:172:74: Error: The getter 'valueType'
isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
abstract class $notifierTypedefName extends $notifierBaseType<${provider.valueType}> {
^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:175:14: Error: The getter 'createdType' isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
${provider.createdType} build($parameterDefinition);
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:180:14: Error: The getter 'createdType' isn't defined for the class 'ClassBasedProviderDeclaration'.
- 'ClassBasedProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'createdType'.
${provider.createdType} runNotifierBuild(
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:248:45: Error: The getter 'exposedType' isn't defined for the class 'GeneratorProviderDeclaration'.
- 'GeneratorProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'exposedType'.
class $familyName extends Family<${provider.exposedType}> {
^^^^^^^^^^^
/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_generator-2.3.4/lib/src/templates/family.dart:332:43: Error: The getter 'valueType'
isn't defined for the class 'GeneratorProviderDeclaration'.
- 'GeneratorProviderDeclaration' is from 'package:riverpod_analyzer_utils/src/riverpod_ast.dart' ('/C:/Users/user@name/AppData/Local/Pub/Cache/hosted/pub.dev/riverpod_analyzer_utils-0.4.1/lib/src/riverpod_ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'valueType'.
mixin $refNameImpl on $refType<${provider.valueType}> {
^^^^^^^^^
[INFO] Bootstrap:Precompiling build script... completed, took 1.9s
[SEVERE] Bootstrap:
Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
pubspec.yaml:
name: aa
description: A new Flutter project.
publish_to: "none"
version: 0.1.0
environment:
sdk: ">=3.1.4 <4.0.0"
dependencies:
flutter:
sdk: flutter
flutter_riverpod: ^2.4.4
riverpod_annotation: ^2.2.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0
riverpod_generator: ^2.3.4
build_runner: ^2.4.6
custom_lint: ^0.5.4
riverpod_lint: ^2.0.2
flutter:
uses-material-design: true
我已经尝试过的:
-
flutter clean
->flutter pub cache clean
->dart run build_runner build clean
- 尝试所有 riverpod 依赖项(包括 dev 依赖项)的先前工作版本
- 完全重新安装 Flutter 并删除 appdata/Local/Pub 文件夹;并从 Android Studio 更新平台工具、sdk 等。
-
多次尝试更新依赖项
flutter pub upgrade --major-versions
- 经历过 这个 和 这个
我已经卡在这一点上两天了,找不到解决办法。在这里问这个问题对我来说是最后的选择。如果需要,请询问更多信息,并为我提供解决方案以重新开始练习。
似乎最新版本的 riverpod 无法正常工作。此问题提供了更多背景信息: https://github.com/rrousselGit/riverpod/issues/2943
编辑:对我而言,一种有效的解决方法是使用 riverpod_generator 3.0.0-dev.3。请参阅此评论: https://github.com/rrousselGit/riverpod/issues/3005#issuecomment-1766892690
riverpod_generator 和 riverpod_lint 插件的最新版本(截至撰写答案时)是:
riverpod_generator: 2.3.4
riverpod_lint: 2.3.1
根据 @MatthewWong 提供的来源,riverpod 的开发人员本人声称
a breaking change landed in riverpod_analyzer_util with an incorrect version number bump.
-Remi Rousselet [source]
因此截至目前,有两种解决方法:
-
正如 @MatthewWong 的来源所述,使用:
riverpod_generator:3.0.0-dev.3 riverpod_lint:^2.3.1
如果需要最新(工作)开发版本。
-
如果需要最新的稳定版本,则两个插件的以下版本组合都可以正常工作:
riverpod_generator:2.3.3 riverpod_lint:2.1.0
在
riverpod_generator
中进行必要的更改之前,这些解决方法效果良好。
无需降级 Flutter SDK,并且该解决方法适用于最新的 Dart 和 Flutter SDK 版本。