Why build_runner watch command is not working?

489 views Asked by At

I have this flutter project I've been working on and I need code generation for various reasons, such as riverpod providers and freezed models. So I'm using build_runner package to generate this .g.dart files, but suddenly when I run dart run build_runner watch I'm getting this error:

[INFO] Generating build script completed, took 152ms
[WARNING] ../../../../../.pub-cache/hosted/pub.dev/riverpod_generator-3.0.0-dev.4/lib/src/templates/family.dart:230:48: Error: The getter 'metadata' isn't defined for the class 'AstNode'.
 - 'AstNode' 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 'metadata'.
    final meta = metaAnnotations(provider.node.metadata);
                                               ^^^^^^^^
[INFO] Precompiling build script... completed, took 625ms
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

I have seen several post regarding this issue but any of the suggested answers seems to work. So I have tried several things: dart run build_runner build --delete-conflicting-outputs Delete pubspec.lock file flutter clean and flutter pub get Upgrade packages to latest versions with flutter pub upgrade Adding the analyzer dependency package as suggested in one post. Tried dart run build_runner doctor but got the same output. I also tried flutter chache repair and flutter pub get and delete manually the cache stored int.dart_tool/ directory but nothing is working. I've been stuck in this for hours with no avail, and I've no idea what might be wrong. Here's my pubscpec.yaml file

name: myapp
description: A new Flutter project.
publish_to: none
version: 1.0.0+1
environment:
  sdk: '>=3.0.5 <4.0.0'
  flutter: ">=3.0.0"
  
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  flutter_riverpod: ^2.3.6
  riverpod_annotation: ^2.2.0
  analyzer:
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  riverpod_generator: ^3.0.0-dev.3
  riverpod_lint: ^2.3.0
  build_runner: ^2.4.6
flutter:
  assets:
    - lib/shared/assets/images/
  fonts:
    - family: Mont-Bold
      fonts:
        - asset: lib/shared/assets/fonts/Mont-Bold.otf
    - family: Mont-SemiBold
      fonts:
        - asset: lib/shared/assets/fonts/Mont-SemiBold.otf
    - family: Mont-Heavy
      fonts:
        - asset: lib/shared/assets/fonts/Mont-Heavy.otf
uses-material-design: true
1

There are 1 answers

1
Dhafin Rayhan On BEST ANSWER

There's a problem with version 3.0.0-dev.4 of riverpod_generator, so temporarily you can strictly use 3.0.0-dev.3 by removing the ^:

dev_dependencies:
  riverpod_generator: 3.0.0-dev.3