Flutter ferry: LateInitializationError: Field ‘exports’ has not been initialized

Today I stumbled over an issue in flutter using ferry, that took me quite a while to debug and there was no information around on what the problem was.

While generating the types build_runner would end up in a loop and I got the following error message:

flutter pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 412ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[WARNING] Throwing away cached asset graph because the build phases have changed. This most commonly would happen as a result of adding a new dependency or updating your dependencies.
[INFO] Cleaning up outputs from previous builds....
[INFO] Cleaning up outputs from previous builds. completed, took 3ms
[INFO] Generating build script...
[INFO] Generating build script completed, took 89ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 805ms
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 612ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Deleting 2 declared outputs which already existed on disk.
[INFO] Checking for unexpected pre-existing outputs. completed, took 3ms
[INFO] Running build...
[INFO] 1.1s elapsed, 20/21 actions completed.
[INFO] 2.4s elapsed, 20/21 actions completed.
[INFO] 3.4s elapsed, 21/37 actions completed.
[INFO] 4.5s elapsed, 21/37 actions completed.
[INFO] 5.5s elapsed, 21/37 actions completed.
[INFO] 6.6s elapsed, 21/37 actions completed.
[SEVERE] gql_build:serializer_builder on lib/$lib$:
LateInitializationError: Field 'exports' has not been initialized.
#0 LibraryReader.exports (package:analyzer/src/summary2/bundle_reader.dart)
#1 LinkedElementFactory.exportsOfLibrary (package:analyzer/src/summary2/linked_element_factory.dart:156:20)
#2 LinkedElementFactory.buildExportNamespace (package:analyzer/src/summary2/linked_element_factory.dart:51:30)
#3 LibraryElementImpl.exportNamespace (package:analyzer/src/dart/element/element.dart:3653:42)
#4 NamespaceBuilder._getExportMapping (package:analyzer/src/dart/resolver/scope.dart:271:20)
#5 NamespaceBuilder.getImportedElements (package:analyzer/src/dart/resolver/scope.dart:211:15)
#6 new PrefixScope (package:analyzer/src/dart/element/scope.dart:181:48)
#7 new _LibraryImportScope (package:analyzer/src/dart/element/scope.dart:295:28)
#8 new LibraryScope (package:analyzer/src/dart/element/scope.dart:106:15)
#9 LibraryElementImpl.scope (package:analyzer/src/dart/element/element.dart:3865:23)
#10 LibraryBuilder.buildScope (package:analyzer/src/summary2/library_builder.dart:134:21)
#11 Linker._computeLibraryScopes (package:analyzer/src/summary2/link.dart:170:15)
#12 Linker._buildOutlines (package:analyzer/src/summary2/link.dart:98:5)
#13 Linker.link (package:analyzer/src/summary2/link.dart:78:5)
#14 link (package:analyzer/src/summary2/link.dart:35:10)
#15 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:172:24)
#16 SetMixin.forEach (dart:collection/set.dart:142:30)
#17 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:110:32)
#18 SetMixin.forEach (dart:collection/set.dart:142:30)
#19 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:110:32)
#20 SetMixin.forEach (dart:collection/set.dart:142:30)
#21 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:110:32)
#22 SetMixin.forEach (dart:collection/set.dart:142:30)
#23 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:110:32)
#24 SetMixin.forEach (dart:collection/set.dart:142:30)
#25 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:110:32)
#26 SetMixin.forEach (dart:collection/set.dart:142:30)
#27 LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:110:32)
#28 LibraryContext.load2.<anonymous closure> (package:analyzer/src/dart/analysis/library_context.dart:203:7)
#29 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#30 LibraryContext.load2 (package:analyzer/src/dart/analysis/library_context.dart:201:12)
#31 AnalysisDriver._createLibraryContext (package:analyzer/src/dart/analysis/driver.dart:1848:22)
#32 AnalysisDriver._computeUnitElement.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1760:28)
#33 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#34 AnalysisDriver._computeUnitElement (package:analyzer/src/dart/analysis/driver.dart:1758:20)
#35 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1342:35)
#36 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2334:24)
<asynchronous suspension>
[INFO] 14.6s elapsed, 21/37 actions completed.
[INFO] 15.7s elapsed, 21/37 actions completed.
[INFO] 16.8s elapsed, 21/37 actions completed.
[INFO] 17.9s elapsed, 21/37 actions completed.
[WARNING] No actions completed for 15.1s, waiting on:
- built_value_generator:built_value on lib/screens/club_entry_detail_screen.dart
- built_value_generator:built_value on lib/screens/club_listing_screen.dart
- built_value_generator:built_value on lib/graphql/hooks/use_get_club_query/use_get_club_query.dart
- built_value_generator:built_value on lib/graphql/hooks/use_get_clubs_query/use_get_clubs_query.dart
- built_value_generator:built_value on lib/widgets/club_entry_item/club_entry_item.dart
.. and 11 more
[INFO] 19.0s elapsed, 21/37 actions completed.
[INFO] 20.1s elapsed, 21/37 actions completed.
[INFO] 21.2s elapsed, 21/37 actions completed.
[INFO] 22.3s elapsed, 21/37 actions completed.
[INFO] 23.4s elapsed, 21/37 actions completed.
[INFO] 24.5s elapsed, 21/37 actions completed.
[INFO] 25.6s elapsed, 21/37 actions completed.
[INFO] 26.7s elapsed, 21/37 actions completed.
[INFO] 27.8s elapsed, 21/37 actions completed.
[INFO] 28.9s elapsed, 21/37 actions completed.
[INFO] 30.0s elapsed, 21/37 actions completed.
[INFO] 31.1s elapsed, 21/37 actions completed.
[INFO] 32.2s elapsed, 21/37 actions completed.
[WARNING] No actions completed for 15.1s, waiting on:
- built_value_generator:built_value on lib/screens/club_entry_detail_screen.dart
- built_value_generator:built_value on lib/screens/club_listing_screen.dart
- built_value_generator:built_value on lib/graphql/hooks/use_get_club_query/use_get_club_query.dart
- built_value_generator:built_value on lib/graphql/hooks/use_get_clubs_query/use_get_clubs_query.dart
- built_value_generator:built_value on lib/widgets/club_entry_item/club_entry_item.dart
.. and 11 more
[INFO] 34.1s elapsed, 21/37 actions completed.
[INFO] 35.2s elapsed, 21/37 actions completed.
...
...
...

The solution for me was to just delete the gql.g.dart and gql.dart files.
BUT and that is what took me longer, not just from the queries and fragments, but also the schema.xxx.dart and serializer.xxx.dart files in the root right next to my schema.graphql file.