Dropsource / monarch

Monarch is a tool for building Flutter widgets in isolation. It makes it easy to build, test and debug complex UIs.
https://monarchapp.io
MIT License
427 stars 21 forks source link

After upgrade to 3.5.1, build_runner fails #101

Closed philipmjohnson closed 1 year ago

philipmjohnson commented 1 year ago

I upgraded Monarch to 3.5.1 from 3.0.0, and now build_runner fails:

% ./build_runner.sh
+ flutter pub run build_runner watch --delete-conflicting-outputs
Deprecated. Use `dart run` instead.
Building package executable... (3.3s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 194ms
[INFO] Setting up file watchers completed, took 5ms
[INFO] Waiting for all file watchers to be ready completed, took 200ms
[INFO] Reading cached asset graph completed, took 138ms
[INFO] Checking for updates since last build completed, took 621ms
[WARNING] monarch|lib/src/builders/meta_stories_generator.dart was not found in the asset graph, incremental builds will not work.
 This probably means you don't have your dependencies specified fully in your pubspec.yaml.
[WARNING] Invalidating asset graph due to build script update!
[INFO] Cleaning up outputs from previous builds. completed, took 9ms
[INFO] Terminating. No further builds will be scheduled
[INFO] Builds finished. Safe to exit
[INFO] Generating build script completed, took 50ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[WARNING] ../../../.pub-cache/hosted/pub.dev/monarch-3.5.1/lib/src/builders/meta_stories_builder.dart:71:39: 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.10.0/lib/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'name2'.
      var returnTypeName = returnType.name2.lexeme;
                                      ^^^^^
[INFO] Precompiling build script... completed, took 3.9s
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

Reverting back to Monarch 3.0.0 in pubspec.yaml and running flutter pub get results in build_runner being successful again.

Here's my current environment:

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.0, on macOS 13.3.1 22E772610a darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Monarch version:

% monarch --version
Monarch version 2.1.8

Monarch modules:
- cli: 3.0.3
- controller: 1.3.0
- platform_app: 2.1.0
- preview_api: 2.2.0

Revision:
74f6f37c95e5af0130da0c527fb4400db27a4563

Pubspec.yaml:

name: ggc_app
description: Geo Garden Club app
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: '>=2.18.4 <3.0.0'
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # Theme stuff
  flutter_native_splash: ^2.2.14
  flex_color_scheme: ^7.0.3
  badges: ^3.0.3
  flutter_markdown: ^0.6.13
  # Form processing
  flutter_form_builder: '>=7.7.0'
  form_builder_validators: '>=8.4.0'
  intl: '>=0.17.0'
  # Riverpod
  flutter_riverpod: ^2.3.5
  riverpod_annotation: ^2.1.1
  # Firebase
  firebase_core: ^2.4.1
  firebase_auth: ^4.2.10
  cloud_firestore: ^4.3.1
  firebase_ui_auth: ^1.1.7
  # Freezed
  freezed_annotation: ^2.2.0
  json_annotation: ^4.8.0
  #Misc
  cached_network_image: ^3.2.3
  go_router: ^6.5.5
  google_fonts: ^4.0.3
  logger: ^1.1.0
  monarch_annotations: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  build_runner: ^2.1.11
  riverpod_generator: ^2.2.1
  riverpod_lint: ^1.3.1
  custom_lint: ^0.3.4
  freezed: ^2.3.2
  json_serializable: ^6.6.1
  monarch: ^3.0.0
  flutter_gen: ^5.3.0

flutter_native_splash:
  image: assets/images/ggc.png
  color: "#43b02a"

flutter:
  uses-material-design: true
  # Enable generation of localized Strings from arb files.
  generate: true
  assets:
    - assets/images/
    - assets/initialData/
    - assets/monarchData/

Please let me know if there is any other information I should provide

fertrig commented 1 year ago

A few things to try:

  1. build_runner on Flutter 3.10 should use dart run build_runner..., not flutter pub run build_runner.... If you are manually running build_runner, then please try it with dart run.

  2. Can you run flutter pub upgrade? Your project is using analyzer 5.10.0. The new monarch package expects analyzer 5.12.0. I think I missed that constraint in the monarch pubspec. I'll do some testing and then release a new version of the monarch package. In the meantime, I think flutter pub upgrade should fix your issue.

  3. Also, Flutter 3.10 uses Dart 3.0.0, and your pubspec says sdk: '>=2.18.4 <3.0.0'. You might want to change that to sdk: '>=2.18.4 <4.0.0'.

philipmjohnson commented 1 year ago

@fertrig Thanks so much! Your suggestions resolved the problem. For anyone else who stumbles across this, flutter pub upgrade, and least for my configuration, did not get analyzer to 5.12.0. When I added it explicitly to dev_dependencies, then upgrade failed due to incompatible version constraints. The solution was to stop "pinning" the versions in dev_dependencies and just specify a lower bound. Once I did that, everything worked great. Here's my fixed pubspec.yml for reference purposes:

name: ggc_app
description: Geo Garden Club app
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: '>=2.18.4 <4.0.0'
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # Theme stuff
  flutter_native_splash: ^2.2.14
  flex_color_scheme: ^7.0.3
  badges: ^3.0.3
  flutter_markdown: ^0.6.13
  # Form processing
  flutter_form_builder: '>=7.7.0'
  form_builder_validators: '>=8.4.0'
  intl: '>=0.17.0'
  # Riverpod
  flutter_riverpod: ^2.3.5
  riverpod_annotation: ^2.1.1
  # Firebase
  firebase_core: ^2.4.1
  firebase_auth: ^4.2.10
  cloud_firestore: ^4.3.1
  firebase_ui_auth: ^1.1.7
  # Freezed
  freezed_annotation: ^2.2.0
  json_annotation: ^4.8.0
  #Misc
  cached_network_image: ^3.2.3
  go_router: ^6.5.5
  google_fonts: ^4.0.3
  logger: ^1.1.0
  monarch_annotations: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: '>=2.0.0'
  build_runner: '>=2.1.11'
  riverpod_generator: '>=2.2.1'
  riverpod_lint: '>=1.3.1'
  custom_lint: '>=0.3.4'
  freezed: '>=2.3.2'
  json_serializable: '>=6.6.1'
  monarch: '>=3.5.1'
  flutter_gen: '>=5.3.0'
  analyzer: '>=5.12.0'

flutter_native_splash:
  image: assets/images/ggc.png
  color: "#43b02a"

flutter:
  uses-material-design: true
  # Enable generation of localized Strings from arb files.
  generate: true
  assets:
    - assets/images/
    - assets/initialData/
    - assets/monarchData/