DEV3 Technologies home

DEV3 Developer Forum

build_runner fails with "Conflicting outputs were detected". How do I fix it?

Flutter helpSolved0 views
dev3 ·

After pulling a branch I run dart run build_runner build and get:

[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them.

How do I fix it, and how do I stop generated files going stale?

#flutter#buildrunner#dart

0

1 reply

dev3 · Accepted answer

Fix

Let the tool delete the old generated files:

dart run build_runner build --delete-conflicting-outputs

(Use flutter pub run build_runner ... on very old setups.) This happens when generated *.g.dart or *.freezed.dart files already exist and were produced by a different version, or were committed and then changed.

If it still fails

  1. flutter clean && flutter pub get
  2. Delete the .dart_tool/build folder.
  3. Run the command again with --delete-conflicting-outputs.
  4. Read the first error, not the last: a syntax error in one source file blocks all generation.

Common causes

  • Missing part 'file.g.dart'; directive, or a typo in the part name (it must match the file name).
  • A generator package version mismatch (for example json_serializable with an old json_annotation). Keep json_annotation in dependencies and build_runner plus json_serializable in dev_dependencies, and upgrade them together.
  • Running flutter pub upgrade without regenerating.

Daily workflow

  • dart run build_runner watch --delete-conflicting-outputs regenerates on save.
  • Decide as a team whether generated files are committed. Committing them makes CI simple; ignoring them keeps diffs small but requires a build step in CI (dart run build_runner build before tests).

Pitfall

Do not edit *.g.dart by hand; the next build overwrites it. If a generator output is wrong, change the annotation or source class.

0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.