Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aliyazdi75 opened this issue Sep 23, 2020 · 78 comments · Fixed by flutter/flutter#68206
Closed

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

aliyazdi75 opened this issue Sep 23, 2020 · 78 comments · Fixed by flutter/flutter#68206

Comments

@aliyazdi75
Copy link

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
Copy link
Contributor

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
Copy link
Author

aliyazdi75 commented Sep 23, 2020

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
Copy link
Contributor

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
Copy link
Author

@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
Copy link
Author

aliyazdi75 commented Sep 23, 2020

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
Copy link
Contributor

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
Copy link
Author

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
Copy link

shihaohong commented Sep 24, 2020

@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
Copy link
Contributor

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

@jakemac53
Copy link
Contributor

jakemac53 commented Sep 24, 2020

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
Copy link
Contributor

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

@shihaohong
Copy link

I can take a stab at it!

@SandroMaglione
Copy link

SandroMaglione commented Oct 2, 2020

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
Copy link

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
Copy link

mark-nicepants commented Oct 5, 2020

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
Copy link

raiFork commented Oct 6, 2020

Thanks @mark-apn worked for me too

@DenisBogatirov
Copy link

Same issue for me. Any news?

@KlausJokisuo

This comment has been minimized.

@jakemac53

This comment has been minimized.

@KlausJokisuo

This comment has been minimized.

@jakemac53

This comment has been minimized.

@jakemac53
Copy link
Contributor

@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

This comment has been minimized.

@DenisBogatirov
Copy link

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
Copy link

Hi all, thank you for your patience. flutter/flutter#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
Copy link

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
Copy link
Contributor

jakemac53 commented Oct 19, 2020

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).

@AleksandarSavic95
Copy link

For some weird reason, running flutter packages pub get instead of flutter pub get solved my issue.

Before that I ran flutter clean and deleted pubspec.lock. I did not have to make any changes in my project manually.

flutter packages pub get works for me. Any links about the difference between flutter pub get and flutter packages pub get. I think they should be the same thing.

I thought they are the same, based on a stackoverflow answer , but it turns out they are not..

@maks
Copy link

maks commented Mar 18, 2022

sigh I seem to have just run into this too. On Flutter stable (Flutter 2.10.3), after I changed my l10n.yaml to have synthetic-package: false (and keeping existing generate: true in pubspec.yml) the next time I went to run build_runner for json_serialisable I got the Unhandled exception: Bad state: Unable to generate package graph, error mentioned here.

Then doing a:

flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs

Still gave the same error. Running gen-l10n also does **not*8 fix the issue via flutter/flutter#68206 as mentioned previously because I'm explicitly not using a synthetic package.
What does fix it is instead is running flutter packages pub get and then running builder runner.

Like @AleksandarSavic95 I am confused as to why one works and the other doesn't as I too thought they were aliases to the same command?

@jakemac53 Could this issue please be reopened?

@jakemac53
Copy link
Contributor

Possibly flutter packages pub get creates the package (including pubspec) but flutter pub get does not?

In any case though I would open a new issue on the flutter repo. All packages must have a pubspec, and they must declare their used dependencies. If they aren't published on pub then the flutter tool should put publish_to: none to indicate that. But the pubspec must exist for build_runner to work properly.

@dvird
Copy link

dvird commented Mar 23, 2022

Best way to solve it is manually.

create in folder ".dart_tool" in your project environment folder called "flutter_gen"
then create in the folder "flutter_gen" file called "pubspec.yaml"
then write in "pubspec.yaml" this text:
"
name: sad
description: sad
"

good luck

in case of more problems:
add this to your project pubspec.yaml

dependency_overrides:
analyzer: 3.3.0

then flutter clean, then flutter pub get

@kafumi
Copy link

kafumi commented Apr 21, 2022

Deleting generate: true from pubspec.yaml works for me. This change will stop automatic generation of l10n.dart but I can still generate the file by manually executing flutter gen-l10n command.

I understand generate: true in pubspec.yaml is not compatible with synthetic-package: false in l10n.yaml. So we need to change either of generate: true or synthetic-package: false.

dkajiwara added a commit to dkajiwara/dkajiwara.github.io that referenced this issue Jul 28, 2022
@viroth-ty
Copy link

You don't need l10n, remove
generate: true in
`

flutter:
     uses-material-design: true
     generate: true

`

@rahmanrezaee
Copy link

rahmanrezaee commented Sep 18, 2022

I just run flutter clean and then flutter pub get
may u need this command also
flutter pub run build_runner watch --delete-conflicting-outputs

Happy Codes :)

@AlexV525
Copy link

Simply relying on flutter_gen as a dev_denpendencies will solve the issue.

@ScottS2017
Copy link

April '23, it happened again to me after a clean. What fixed it was changing the sequence of commands.

  • flutter pub get
    then
  • flutter gen-l10n
    and only then run build_runner

When I tried to run build_runner before gen-l10n, I had the error. Swapping them in the sequence fixed it.

hawkkiller added a commit to hawkkiller/sizzle_starter that referenced this issue Apr 26, 2023
hawkkiller added a commit to hawkkiller/sizzle_starter that referenced this issue Apr 26, 2023
* Refactored localization

- Created feature localizations
- Created Delegates
- Refactored folder structure a bit

* Fixed issue caused by dart-lang/build/issues/2835

* Fixed issue by creating typedef
@RyoheiKawamon
Copy link

Simply relying on flutter_gen as a dev_denpendencies will solve the issue.

I THINK THIS IS THE ANSWER.

@asafratzon
Copy link

asafratzon commented Sep 20, 2023

For me the minimal cleanup needed is .dart_tool/package_config.json, so I run the following:

rm .dart_tool/package_config.json && dart run build_runner watch --delete-conflicting-outputs

@treble-maker123
Copy link

Possibly flutter packages pub get creates the package (including pubspec) but flutter pub get does not?

In any case though I would open a new issue on the flutter repo. All packages must have a pubspec, and they must declare their used dependencies. If they aren't published on pub then the flutter tool should put publish_to: none to indicate that. But the pubspec must exist for build_runner to work properly.

Replacing flutter packages get with flutter packages pub get fixed this issue for me.

@ghost
Copy link

ghost commented Nov 1, 2023

I had a similar issue developing on Chrome OS Flex:

chime@penguin:~/dev/x$ dart run build_runner build
Building package executable... (5.4s)
Built build_runner:build_runner.
Unhandled exception:
Bad state: Unable to generate package graph, no `/home/chime/dev/x/.dart_tool/flutter_gen/pubspec.yaml` found.
#0      _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:268:5)
#1      _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:242:21)
#2      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:120:33)
<asynchronous suspension>
#3      main (file:///home/chime/.pub-cache/hosted/pub.dev/build_runner-2.4.6/bin/build_runner.dart:27:30)
<asynchronous suspension>

I was able to fix it by changing generate from true to false in my pubspec.yaml like so:

flutter:
  uses-material-design: true
  generate: false 

Is it some issue with intl package?

@natebosch
Copy link
Member

This is being discussed and tracked at dart-lang/sdk#53696

@codewithmustafa
Copy link

codewithmustafa commented Jan 23, 2024

I got the same exception but my solution was strange:

I generated localization code and files first with:

flutter gen-l10n

and then generating others wıth:

flutter pub run build_runner build

worked seamlessly.

@markbeij
Copy link

This is being discussed and tracked at dart-lang/sdk#53696

That issue doesn't seem to fix this issue.
@jakemac53 can we reopen this issue?

@natebosch
Copy link
Member

The linked issue has been reopened. Unless we suspect there is a different problem than the conflict between dart pub get and flutter pub get we should keep the conversation at dart-lang/sdk#53696

If there is a different issue than the conflict in package resolutions it can be opened as a new issue in this repo.

@WongueShin
Copy link

I'm not sure why this phenomenon occurs, but I have identified the following reproduction conditions and a solution.

Reproduction conditions:

If you run pub get even once in a Flutter package that depends on both l10n and build_runner, errors will occur in all subsequent "dart run build_runner build" operations.

Solution:

Delete the pubspec.lock file right before each "dart run build_runner build".
I have automated this process with a script that I am currently using.

I hope my case will be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet