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

Using dart run conflicts with flutter pub get #53696

Open
ziqq opened this issue Oct 5, 2023 · 22 comments
Open

Using dart run conflicts with flutter pub get #53696

ziqq opened this issue Oct 5, 2023 · 22 comments
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-run Issues related to 'dart run'

Comments

@ziqq
Copy link

ziqq commented Oct 5, 2023

Every time after running dart run build_runner build --delete-conflicting-outputs command you have to run flutter pub get to remove the error below.

image
@jakemac53
Copy link
Contributor

Can you provide a small repro example, ideally as a git repo?

@jakemac53 jakemac53 added the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Oct 5, 2023
@natebosch natebosch changed the title [build_runner] Need run flutter pub get every time after dart run build_runner build --delete-conflicting-outputs Using dart run conflicts with flutter pub get Oct 6, 2023
@natebosch natebosch transferred this issue from dart-lang/build Oct 6, 2023
@natebosch
Copy link
Member

I think this is because dart run build_runner runs a dart pub get.

dart pub get conflicts with flutter pub get because the latter creates a synthetic package:flutter_gen into the solve.

cc @mit-mit

@natebosch natebosch added area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-run Issues related to 'dart run' and removed needs-info We need additional information from the issue author (auto-closed after 14 days if no response) labels Oct 6, 2023
@jakemac53
Copy link
Contributor

I didn't think you could do a dart pub get inside of a flutter package?

@ziqq
Copy link
Author

ziqq commented Oct 9, 2023

I think this is because dart run build_runner runs a dart pub get.

dart pub get conflicts with flutter pub get because the latter creates a synthetic package:flutter_gen into the solve.

cc @mit-mit

Yep flutter run build_runner working fine, but build_runner requires dart run build_runner

image

@mit-mit
Copy link
Member

mit-mit commented Oct 9, 2023

cc @jonasfj @sigurdm

@sigurdm
Copy link
Contributor

sigurdm commented Oct 9, 2023

Yeah - this is a real problem.

A workaround is to run flutter pub get first to create the flutter_gen package.

But we should really find a solution for the flutter_gen package (either avoid it, or create proper support for it in pub) it keeps on creating problems in different places.

@christopherfujino I recently mentioned that we should look into this soon.

@lucavenir
Copy link

lucavenir commented Nov 30, 2023

As mentioned in here the conflicts stands because flutter has its own generator (l10n wise).

Personally I stumbled on this because I've generated files in a custom folder with the following l10n configuration:

arb-dir: lib/l10n/arb
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
output-dir: lib/l10n/gen
synthetic-package: false
nullable-getter: false

If it can help, there are two workarounds:

  1. Run packages get instead of just get, aka:
flutter clean && flutter packages get && dart run build_runner build -d
  1. Just add flutter_gen as a dev dependency - idk why, but it works (probably this package is used somewhere in between the chain, or maybe one of its inner dependencies, idk)

@bwilkerson
Copy link
Member

@jacob314 FYI

@ziqq
Copy link
Author

ziqq commented Dec 1, 2023

Hi and thx everyone, my problem is resolved in Flutter 3.16.1. Now dart run build_runner work correctly.

@ziqq ziqq closed this as completed Dec 1, 2023
@dovahkrid
Copy link

Hi and thx everyone, my problem is resolved in Flutter 3.16.1. Now dart run build_runner work correctly.

I'm on Flutter 3.16.5 and still got this issue

@markbeij
Copy link

@natebosch can we reopen this issue?

@sigurdm sigurdm reopened this Jan 26, 2024
@rydmike
Copy link

rydmike commented Feb 5, 2024

Using Flutter 3.16.9 and a setup very much like #53696 (comment) with its `l10n.yaml´ file.

I'm having this issue as well. The weird workaround (option 2) of adding flutter_gen as a dev dep, worked for me too, using it as temp workaround for now.

@ziqq
Copy link
Author

ziqq commented Feb 22, 2024

I stopped receiving this error message, unfortunately I don’t remember exactly what led to this, but here is my configuration.

Flutter: 3.19.1

l10n.yaml
arb-dir: lib/src/core/localization/translations
template-arb-file: app_en.arb
output-localization-file: app_localizations.g.dart
preferred-supported-locales:
- en

nullable-getter: false
use-deferred-loading: true
Command
dart --disable-analytics && dart run build_runner build --delete-conflicting-outputs --release

@ziqq
Copy link
Author

ziqq commented Feb 22, 2024

If any more can't catch this error, then i think maybe close this issue.

@rydmike
Copy link

rydmike commented Feb 22, 2024

I will check with my case as on Flutter 3.19.1 as well, I'll be back soon.

@rydmike
Copy link

rydmike commented Feb 23, 2024

Tested with Flutter 3.19.1. No change, still fails.

If I remove the known workaround of having flutter_gen: as a dev dependency, build runner fails as before, with error:

Unhandled exception:
Bad state: Unable to generate package graph, no `/Users/rydmike/dev/code/talo/.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:///Users/rydmike/.pub-cache/hosted/pub.dev/build_runner-2.4.8/bin/build_runner.dart:27:30)
<asynchronous suspension>

My l10n.yaml file:

arb-dir: lib/core/localization/translations
template-arb-file: app_en.arb
output-dir: lib/core/localization/generated
nullable-getter: false
synthetic-package: false
use-deferred-loading: true

Putting flutter_gen back, fixes the issue, and build runner works again.

@lucavenir
Copy link

lucavenir commented Feb 26, 2024

I keep having problems with this, even worse now.
I am unable to consistently run flutter gen-l10n and to correctly obtain AppLocalizations.

I'm doing nothing different than what described above, but sometimes cleaning, pub-getting and generating code completely breaks l10n in a state in which I can't recover from.

The only way I "broke away" from this stalemate is by... running the application. But without the help of my IDE (VS Code). Yes, plainly running flutter run swipes the whole problem under a rug.

.. Couldn't this whole experience improve, somehow?

@mpep2
Copy link

mpep2 commented Feb 28, 2024

I am also facing the issue with dart run, using flutter pub run build_runner build --delete-conflicting-outputs fixes the problem temporarily

@dkbast
Copy link

dkbast commented Apr 15, 2024

I get the same issue on 3.19.5 - the dev dependencies workaround works for me as well

@hpoul
Copy link

hpoul commented May 7, 2024

Same issue in 3.19.6, (l10n.yaml with synthetic-package: false, pubspec.yaml with generate: true but additionally using the flutter_gen package from pub which makes this even more confusing.. (or rather i've only used flutter_gen_runner until now, but adding flutter_gen in addition to it seems to do the trick)

@LeonardoRosaa
Copy link

LeonardoRosaa commented May 7, 2024

Same issue here using Flutter 3.19.5. However, I fixed it by removing the generate flag from the pubspec.yaml file and rewriting my l10n.yaml configuration as follows:

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-dir: lib/l10n/gen
nullable-getter: false
synthetic-package: false
use-deferred-loading: true

After making these changes, it is necessary to rerun the app to generate the .arb files correctly.

@Yukinosuke-Takada
Copy link

@hpoul Had the same issue. I agree with your solution. It was important to make synthetic-package to false to avoid package name conflict. I have written this in detail here (stackoverflow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-run Issues related to 'dart run'
Projects
None yet
Development

No branches or pull requests