dart-lang / build

A build system for Dart written in Dart
https://pub.dev/packages/build
BSD 3-Clause "New" or "Revised" License
785 stars 207 forks source link

[build_runner 1.10.3] Bad state: Unable to generate package graph #2835

Closed aliyazdi75 closed 3 years ago

aliyazdi75 commented 4 years ago

build_runner: ^1.10.3 flutter packages pub run build_runner build:

Unhandled exception:
Bad state: Unable to generate package graph, no `/home/aliyazdi75/Documents/AndroidStudioProjects/koja_beram_app/.dart_tool/flutter_gen/pubspec.yaml` found.
#0      _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:235:5)
#1      _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:208:21)
#2      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:97:33)
<asynchronous suspension>
#3      PackageGraph.forThisPackage (package:build_runner_core/src/package_graph/package_graph.dart:110:20)
#4      main (file:///home/aliyazdi75/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.10.3/bin/build_runner.dart:27:49)
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
pub finished with exit code 255

flutter doctor -v:

[✓] Flutter (Channel master, 1.22.0-10.0.pre.317, on Linux, locale en_US.UTF-8)
    • Flutter version 1.22.0-10.0.pre.317 at /home/aliyazdi75/snap/flutter/common/flutter
    • Framework revision 10febea877 (7 hours ago), 2020-09-23 07:22:10 +0200
    • Engine revision 57ee3d4b32
    • Dart version 2.10.0 (build 2.10.0-156.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /home/aliyazdi75/Android/Sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: /home/aliyazdi75/Application/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[✓] Android Studio (version 4.0)
    • Android Studio at /home/aliyazdi75/Application/android-studio
    • Flutter plugin version 49.0.2
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (3 available)
    • Linux (desktop)  • linux      • linux-x64      • Linux
    • Web Server (web) • web-server • web-javascript • Flutter Tools
    • Chrome (web)     • chrome     • web-javascript • Google Chrome 85.0.4183.12
jakemac53 commented 4 years ago

It sounds like build_runner was ran from inside the .dart_tool/flutter_gen directory instead of from the root directory for the package?

aliyazdi75 commented 4 years ago

Hi @jakemac53 No, I was running from the root directory: ~/Documents/AndroidStudioProjects/koja_beram_app$ flutter packages pub run build_runner build Inside my .dart_tool/flutter_gen there is no pubspec.yaml.

jakemac53 commented 4 years ago

The build package doesn't read from the .dart_tool/flutter_gen directory which is why I am confused.

cc @jonahwilliams do you know what the deal is with that?

aliyazdi75 commented 4 years ago

@jakemac53 I am wondering it works for my previous flutter applications, but in my new application doesn't. I don't know is it relevant or not but I have l10n.yaml file and it builds a gen_l10n inside .dart_tool/flutter_gen.

aliyazdi75 commented 4 years ago

I don't know is it relevant or not but I have l10n.yaml file and it builds a gen_l10n inside .dart_tool/flutter_gen.

I tried removing l10n.yaml and then flutter clean and flutter packages pub get and it fixed!

jakemac53 commented 4 years ago

Ok, the build package does require a pubspec.yaml to exist for all packages. It sounds like maybe that was generating some sort of special package that has no pubspec.yaml?

aliyazdi75 commented 4 years ago

Do you mean that gen_l10n should have pubspec.yaml? So, I should submit an issue in flutter repository? Hi @shihaohong, can you help me with this localization issue?

shihaohong commented 4 years ago

@aliyazdi75 .dart_tool/flutter_gen should not contain a pubspec.yaml because it should only contain synthetic packages, such as the gen_l10n synthetic package in your case. It seems like the correct behavior is that build_runner should ignore .dart_tool/flutter_gen (I'm not sure if it should also ignore the rest of .dart_tool) when generating a package graph.

jonahwilliams commented 4 years ago

It wouldn't necessarily be wrong to also generate a pubspec.yaml there, especially if it smooths things over with build runner.

jakemac53 commented 4 years ago

We do require a pubspec. It doesn't have to be a particularly meaningful one, but we do rely on knowning the direct dependencies of each package for a lot of hueristics (for ordering build steps and things). This is a fundamental constraint of the system.

Plenty of other tools expect a pubspec to exist for all packages as well, I would just put a minimal one in there.

jonahwilliams commented 4 years ago

@shihaohong is this something you could take a look at?

shihaohong commented 4 years ago

I can take a stab at it!

SandroMaglione commented 4 years ago

Any news about the issue? Now that Flutter 1.22 is out, I was following the guide to set up the new internationalization system.

The guide says to add a new l10n.yaml file and

flutter:
  # Adds code generation (synthetic package) support 
  generate: true

Inside .dart_tool is generated flutter_gen\gen_l10n with the localization files.

Currently, I am unable to run the generator at all. @shihaohong Is there any workaround or should I wait to include the new internationalization?

SandroMaglione commented 4 years ago

I removed the l10n.yaml and the problem was still there.

The problem error disappears when I remove generate: true from pubspec.yaml. May this information help?

mark-nicepants commented 3 years ago

Same here. (Tried 1.10.1, 1.10.2, 1.10.3)

generate: false will fix the build_runner, but will break the new l10n integration.

Bad state: Unable to generate package graph, no `/Users/mark/Projects/flutter/bunch-flutter/.dart_tool/flutter_gen/pubspec.yaml` found.
#0      _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:235:5)
#1      _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:208:21)
#2      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:97:33)
<asynchronous suspension>
#3      PackageGraph.forThisPackage (package:build_runner_core/src/package_graph/package_graph.dart:110:20)
#4      main (file:///Users/mark/.pub-cache/hosted/pub.dartlang.org/build_runner-1.10.3/bin/build_runner.dart:27:49)
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

If I add a empty pubspec.yaml in the flutter_gen directory. The build is working again

afbeelding

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

dependencies:

dev_dependencies:
raiFork commented 3 years ago

Thanks @mark-apn worked for me too

DenisBogatirov commented 3 years ago

Same issue for me. Any news?

KlausJokisuo commented 3 years ago

Slightly offtopic, but have you guys noticed how slow Buildrunner is nowadays?

jakemac53 commented 3 years ago

@KlausJokinen if you have noticed a regression please do file an issue - it could be due to app size as well but there are things you can do to alleviate that. Most builders by default will end up running on a lot more files than they need to (all dart files...) and especially if they rely on analysis that can be quite expensive for large projects.

KlausJokisuo commented 3 years ago

@KlausJokinen if you have noticed a regression please do file an issue - it could be due to app size as well but there are things you can do to alleviate that. Most builders by default will end up running on a lot more files than they need to (all dart files...) and especially if they rely on analysis that can be quite expensive for large projects.

Thanks @jakemac53. Is it possible to trigger build_runner on a specific file/files?

jakemac53 commented 3 years ago

Yes - there is a command line flag --build-filter which accepts globs of output files to build. But note that it will also generate any files required by those matching files which will mean all transitively imported generated code. That also means any builders you have will still run on all the transitive imports of the primary inputs for the files you are asking it to generate. The result is that in terms of Dart code generation it likely won't help much, but you can try it.

A better option is to configure the generate_for globs for your builders, which will make them only ever run on certain files. Note that for source_gen based builders for instance by default they will run on (and analyze) all Dart files in your package, even the ones that don't need codegen (it does this to determine if it needs to run, looking for annotations). You can configure these to only run on the files you know they need to run on in your build.yaml roughly like this:

targets:
  $default:
    builders:
      json_serializable: # This is the builder "key", which is usually the package name for the builder
        generate_for:
        - lib/models/*.dart
jakemac53 commented 3 years ago

@KlausJokinen I am going to hide our somewhat off topic conversation just to clean up the thread here - if you have further questions please open an issue and we will be happy to discuss there :)

ipcjs commented 3 years ago

just add pubspec.yaml to .dart_tool/flutter_gen can fix the issue: content of pubspec.yaml is this:

dependencies:
DenisBogatirov commented 3 years ago

just add pubspec.yaml to .dart_tool/flutter_gen can fix the issue: content of pubspec.yaml is this:

dependencies:

It's not fix, it's workaround. As soon as tou run flutter clean or new developer in your team clone project they need to create empty pubspec.yaml again

shihaohong commented 3 years ago

Hi all, thank you for your patience. https://github.com/flutter/flutter/pull/68206 should have fixed this issue in master. If there's still any issues surrounding the pubspec.yaml issue and build_runner, please file an issue at https://github.com/flutter/flutter and feel free to cc me in on them.

kuhnroyal commented 3 years ago

I don't see this as a workaround tbh. You can maybe do this for a local checkout but the i10n feature is practically not useable with current stable version for larger teams and existing CI pipelines.

jakemac53 commented 3 years ago

Closing the issue here as it seems this is resolved on the flutter side of things - please re-open an issue on the flutter repo as indicated if you are still experiencing issues (or would like to advocate for a hotfix stable release).

SandroMaglione commented 3 years ago

@shihaohong any idea on when this fix will be released in Flutter stable? Will it be Flutter 1.23 or it may be released in a hotfix?

AlessioCampanelli commented 3 years ago

I solve it installing in my dev_dependencies this package:

https://pub.dev/packages/flutter_gen

DevHachi commented 3 years ago

I am still having this problem. None of the above works for me.

marcusco commented 3 years ago

I am still having this problem. None of the above works for me.

For me too.

reflect-framework commented 3 years ago

I am still having this problem. None of the above works for me.

jakemac53 commented 3 years ago

@shihaohong do you know the status here? Are there still issues open on the flutter side?

aliyazdi75 commented 3 years ago

@jakemac53 I think this works fine as expected. I don't know much about recent comments saying that's not working.

shihaohong commented 3 years ago

It should be working as expected. The most recent comments seem to be spam.

Edit: For anyone still facing the same issue and the fix hasn't resolved your problem, please file an issue in the Flutter repo and tag me in it. Thank you!

marynovskyi commented 3 years ago

Having the same issue: Unhandled exception: Bad state: Unable to generate package graph, no.../.dart_tool/flutter_gen/pubspec.yamlfound.

samu-developments commented 3 years ago

Edit. I had a typo in my l10n.yaml file name, it works for me now!

combi-35 commented 3 years ago

Having the same issue: Unhandled exception: Bad state: Unable to generate package graph, no.../.dart_tool/flutter_gen/pubspec.yamlfound.

Same for me.

lukaglo commented 3 years ago

Had the same issue with Flutter 1.22.5 and l10n package - the workaround with pubspec.yaml in the ...dart_tool\flutter_gen\ worked. I actually copied the project's main pubspec.yaml there. Other methods described in this thread were not successful.

hieubagiang commented 3 years ago

I removed the l10n.yaml and the problem was still there.

The problem error disappears when I remove generate: true from pubspec.yaml. May this information help?

thank you, i'm remove generate:true and it run

jbt-cii commented 3 years ago

I had the same problem.

I resolved it following explanations for "flutter_gen" package: https://pub.dev/packages/flutter_gen/install

So simply by adding "flutter_gen: ^1.3.1" in the "pubspec.yaml" dependencies :

`

dependencies: flutter: sdk: flutter flutter_gen: ^1.3.1 auto_route: ^0.6.9 ...

dev_dependencies:

flutter_test:

sdk: flutter

build_runner: ^1.11.1 auto_route_generator: ^0.6.10

flutter: generate: true

uses-material-design: true

`

Then after I did this: flutter packages pub run build_runner build

Now I have another error but this one :-) ` [INFO] Generating build script... [INFO] Generating build script completed, took 505ms

[INFO] Creating build script snapshot...... [INFO] Creating build script snapshot... completed, took 9.5s

[INFO] Initializing inputs [INFO] FlutterGen Loading ... pubspec.yaml [INFO] Generated: /Users/myhome/Documents/GIT/myproject/lib/gen/assets.gen.dart [INFO] Generated: /Users/myhome/Documents/GIT/myproject/lib/gen/fonts.gen.dart [INFO] FlutterGen finished. [INFO] Building new asset graph... [INFO] Building new asset graph completed, took 487ms

[INFO] Checking for unexpected pre-existing outputs.... [INFO] Checking for unexpected pre-existing outputs. completed, took 1ms

[INFO] Running build... [WARNING] auto_route_generator:autoRouteGenerator on test/widget_test.dart: Your current analyzer version may not fully support your current SDK version.

Please try upgrading to the latest analyzer by running flutter packages upgrade.

Analyzer language version: 2.12.0 SDK language version: 2.13.0

If you are getting this message and have the latest analyzer please file an issue at https://github.com/dart-lang/sdk/issues/new with the title "No published analyzer available for language version 2.13.0". Please search the issue tracker first and thumbs up and/or subscribe to existing issues if present to avoid duplicates. `

salvaterra commented 3 years ago

flutter gen-l10n solved for me

jbt-cii commented 3 years ago

I had another problem trying to use the package "easy_localization". For "flutter channel stable" I had to use the 3.0.0 version of this package. I don't remember exactly but I think I should comment "flutter_gen" because a compatibility problem.

After several modifications in my code I tried to generate again the routes for the package "auto_route". Then I had this error:

✗ flutter packages pub run build_runner build
Unhandled exception: Bad state: Unable to generate package graph, no /Users/myhome/Documents/GIT/myproject/.dart_tool/flutter_gen/pubspec.yaml found.

0 _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:234:5)

1 _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:208:21)

2 PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:97:33)

#3 main (file:///opt/homebrew/Caskroom/flutter/1.22.6/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.11.5/bin/build_runner.dart:28:30) pub finished with exit code 255 => So I uncommented the package "flutter_gen" ✗ flutter packages pub run build_runner build The pubspec.yaml file has changed since the pubspec.lock file was generated, please run "pub get" again. pub finished with exit code 65 ✗ flutter pub get Because no versions of easy_localization_loader match >0.0.2 <0.1.0 and easy_localization_loader 0.0.2 depends on xml ^3.5.0, easy_localization_loader ^0.0.2 requires xml ^3.5.0. And because flutter_gen >=0.0.6 <2.0.0 depends on xml ^4.2.0, easy_localization_loader ^0.0.2 is incompatible with flutter_gen >=0.0.6 <2.0.0. So, because myproject depends on both flutter_gen ^1.3.1 and easy_localization_loader ^0.0.2, version solving failed. Running "flutter pub get" in myproject... pub get failed (1; So, because myproject depends on both flutter_gen ^1.3.1 and easy_localization_loader ^0.0.2, version solving failed.) => So I tried the 2.0.0 version of "flutter_gen" (no effect) and I tried that: ✗ flutter clean Cleaning Xcode workspace... 1 758ms Deleting .dart_tool... 1ms Deleting .packages... 0ms Deleting Generated.xcconfig... 0ms Deleting flutter_export_environment.sh... 0ms Deleting .flutter-plugins-dependencies... 0ms Deleting .flutter-plugins... 0ms ✗ flutter pub get Because no versions of easy_localization match >3.0.0 <4.0.0 and easy_localization 3.0.0 depends on args ^2.0.0, easy_localization ^3.0.0 requires args ^2.0.0. And because flutter_gen >=0.0.11 depends on args ^1.6.0, easy_localization ^3.0.0 is incompatible with flutter_gen >=0.0.11. So, because myproject depends on both flutter_gen ^2.0.0 and easy_localization ^3.0.0, version solving failed. Running "flutter pub get" in myproject... pub get failed (1; So, because myproject depends on both flutter_gen ^2.0.0 and easy_localization ^3.0.0, version solving failed.) => To be able to generate once more the compiled file "router.gr.dart" I should comment the "easy_localization" package in "pubspec.yaml" and then I would be able to generate the file: ✗ flutter packages pub run build_runner build [INFO] Generating build script... [INFO] Generating build script completed, took 515ms [INFO] Creating build script snapshot...... [INFO] Creating build script snapshot... completed, took 8.7s [INFO] There was output on stdout while compiling the build script snapshot, run with `--verbose` to see it (you will need to run a `clean` first to re-snapshot). [INFO] Initializing inputs [INFO] Building new asset graph... [INFO] Building new asset graph completed, took 471ms [INFO] Checking for unexpected pre-existing outputs.... [INFO] Checking for unexpected pre-existing outputs. completed, took 1ms [INFO] Running build... [WARNING] auto_route_generator:autoRouteGenerator on test/widget_test.dart: Your current `analyzer` version may not fully support your current SDK version. Please try upgrading to the latest `analyzer` by running `flutter packages upgrade`. Analyzer language version: 2.12.0 SDK language version: 2.13.0 If you are getting this message and have the latest analyzer please file an issue at https://github.com/dart-lang/sdk/issues/new with the title "No published analyzer available for language version 2.13.0". Please search the issue tracker first and thumbs up and/or subscribe to existing issues if present to avoid duplicates. [INFO] Generating SDK summary... [INFO] 3.3s elapsed, 0/16 actions completed. [INFO] Generating SDK summary completed, took 3.2s [INFO] 4.4s elapsed, 29/30 actions completed. [INFO] 5.4s elapsed, 29/30 actions completed. [INFO] 12.5s elapsed, 29/30 actions completed. [INFO] Running build completed, took 12.9s [INFO] Caching finalized dependency graph... [INFO] Caching finalized dependency graph completed, took 34ms [INFO] Succeeded after 12.9s with 1 outputs (30 actions) => And finally in "pubspec.yaml": - I uncommented once again the "easy_localization" package - I commented once again the "flutter gen" package Strange but with that solution my application worked fine!
jbts6 commented 3 years ago

I solve it installing in my dev_dependencies this package:

https://pub.dev/packages/flutter_gen

It worked

MatrixDev commented 3 years ago

I still have this problem with build_runner 1.12.2 :(

TheFabbiusCorp commented 3 years ago

Hello devs, I think I have come up with a solution to the riddle.

The issue

Although it is written in the official Flutter documentation for internationalization, package intl cannot generate boilerplate code (such as messages_*.dart or l10n.dart) by just running your app. An additional command line is required to generate necessary files, as it is written at the bottom of the official documentation. Unfortunately, package intl_translation is required for that and, of course, at the moment there are conflicts between the latest versions of intl and intl_translation.

At this point, we have identified two use cases:

Solution for those who don't need to (re-)generate l10n files

If you don't need the files, just don't allow their generation:

Solution for those who need to generate l10n files

If you need the precious boilerplate code, and you're using the intl package just for it, then you can safely remove it and replace it with intl_utils. Although intl_utils is not mentioned in the official Flutter documentation (which I think needs to be polished a little), and is not an official Flutter package, it represents an ad-hoc solution for this specific problem and it is also null-safety enabled.

If you're willing to use it instead of intl+build_runner, then:

Hope this helps some lost dev, while waiting for an official Flutter solution. ☺️

dalewking commented 3 years ago

I started seeing this issue again when I switched my l10n.yaml file to say:

synthetic-package: false

It no longer generates a synthetic package, but some other part of flutter seems to think that there must be a synthetic package and fails because it cannot find its pubspec.yaml file

timnew commented 3 years ago

The issue came back when generate: true in pubspec.yml with synthetic-package: false in i10n.yml. It is useful when build a library with l10n support, when I want all the generated code in my lib folder rather than a synth project, but clearly build_tool would think flutter_gen is still a thing, so when it try to find that direct not even exists, it breaks the whole build.

ikurek commented 3 years ago

I can confirm, that issue is still present with generate: true and synthetic-package: false. Is there any workaround other than disabling autogeneration?

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5 20G71 darwin-x64, locale pl-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] IntelliJ IDEA Community Edition (version 2021.1.3)
[✓] VS Code (version 1.58.2)
[✓] Connected device (2 available)

• No issues found!
Lyokone commented 3 years ago

Hi, For our project, we only needed to create an empty pubspec.yaml

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

dependencies:

dev_dependencies:

here: .dart_tool/flutter_gen/pubspec.yaml And the problem went away. Not sure what caused this issue in the first place tho :/