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
433 stars 22 forks source link

`monarch run` yields "Bad State..." #87

Closed philipmjohnson closed 1 year ago

philipmjohnson commented 1 year ago

I am trying to set up a new project following the installation instructions. Everything works OK until I get to monarch run. It appears to start up, but within a few seconds I get an error:

Using flutter sdk at /Users/philipjohnson/flutter/bin/flutter
Enabling Flutter for desktop

Starting Monarch.

Preparing stories...
3.1sec elapsed, 1/2 tasks completed
6.2sec elapsed, 1/2 tasks completed
9.3sec elapsed, 1/2 tasks completed
12.4sec elapsed, 1/2 tasks completed
Preparing stories completed, took 14.7sec.

Launching Monarch app...
Launching Monarch app completed, took 2.8sec.

Attaching to stories...
3.1sec elapsed
6.2sec elapsed
Attaching to stories completed, took 8.9sec.

Setting up stories watch...
3.1sec elapsed
Unhandled exception:
Bad state: Unable to generate package graph, no `/Users/philipjohnson/github/geogardenclub/ggc_app/.dart_tool/flutter_gen/pubspec.yaml` found.
#0      _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:232:5)
#1      _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:206:21)
#2      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:101:33)
<asynchronous suspension>
#3      main (file:///Users/philipjohnson/.pub-cache/hosted/pub.dev/build_runner-2.3.3/bin/build_runner.dart:27:30)
<asynchronous suspension>

[   +2 ms] pub finished with exit code 255

[        ] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:586:7)
           <asynchronous suspension>
           #2      PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:250:5)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1257:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:283:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:91:3)
           <asynchronous suspension>

6.2sec elapsed
9.3sec elapsed
^C
Terminating running tasks...
Done

Once I get this error, if I run monarch run again, I get the error even before the app comes up:

monarch run                                                                      19:11:02
Using flutter sdk at /Users/philipjohnson/flutter/bin/flutter
Enabling Flutter for desktop

Starting Monarch.

Preparing stories...
Unhandled exception:
Bad state: Unable to generate package graph, no `/Users/philipjohnson/github/geogardenclub/ggc_app/.dart_tool/flutter_gen/pubspec.yaml` found.
#0      _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:232:5)
#1      _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:206:21)
#2      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:101:33)
<asynchronous suspension>
#3      main (file:///Users/philipjohnson/.pub-cache/hosted/pub.dev/build_runner-2.3.3/bin/build_runner.dart:27:30)
<asynchronous suspension>

pub finished with exit code 255

Preparing stories (code generation) failed. Exiting.
Re-run with the --verbose flag to get more information
Process did not finish successfully, exit code 255

I can do the following to fix the bad state error:

flutter clean
rm -rf pubspec.lock
flutter packages pub get
flutter pub run build_runner build --delete-conflicting-outputs
cd ios; pod repo update

And then when I run monarch run, the app will come up again, but it will get into the bad state error again within a few seconds.

What can I do to eliminate this error?

fertrig commented 1 year ago

Hi @philipmjohnson, it seems this is an old Flutter issue which has just resurfaced, see this comment.

I'd try the following:

Create a pubspec.yaml in /Users/philipjohnson/github/geogardenclub/ggc_app/.dart_tool/flutter_gen/pubspec.yaml with these contents:

name: test
description: A new Flutter application.
version: 1.0.0

dependencies:

dev_dependencies:

Then try:

flutter pub get
flutter gen-l10n
monarch run

If that doesn't work, try monarch run --delete-conflicting-outputs instead of monarch run.

You can also try moving your flutter_gen under dev_dependencies.

If that doesn't work, then I'd need more details to reproduce. Your pubspec.yaml would be helpful and your flutter doctor output. You could also run monarch run -v which should print out a log file which may be helpful.

My gut tells me this is a flutter_gen issue though.

philipmjohnson commented 1 year ago

Wow, I am grateful for the quick and helpful response! Makes me feel like I chose the right storybook app for Flutter.

I decided to start by moving flutter_gen to dev_dependencies and seeing what happens, since creating the pubspec.yml file manually would need to be redone each time the system is downloaded and built from GitHub. Turns out that this seems to have fixed the problem.

I am excited to move on and get to know Monarch. Thanks again.