0

My question is about project configuration and generatting boilerplate code using build_runner: json_serializable, freezed. We are using melos.

The project is configured as a workspace. It has two packages let's name it:

  • packages/sdk
  • packages/app

app is using sdk.

In both app and sdk packages there are some boilerplate to generate using freezed and json_serializable. In our root pubspec.yaml we have:

name: workspace
publish_to: none
environment:
 sdk: ^3.8.1
workspace:
 - packages/sdk
 - packages/app
dev_dependencies:
 melos: 7.1.0
melos:
 scripts:
 build_runner:
 exec: dart run build_runner build --delete-conflicting-outputs
 description: Run code generation
 packageFilters:
 dependsOn: build_runner

When we execute: melos run build_runner and we select sdk package it ends with success.

After this we try to run this again and select app and we receive such errors:

app:
 Generating the build script.
 Reading the asset graph.
 Checking for updates.
 Updating the asset graph.
 Building, incremental build.
 0s freezed on 20 inputs; lib/feature/dashboard/domain/model/dashboard_tab.dart
 0s freezed on 20 inputs: 1 skipped; lib/feature/dashboard/domain/model/transaction.dart
 0s freezed on 20 inputs: 20 skipped
 0s json_serializable on 40 inputs; lib/feature/dashboard/domain/model/dashboard_tab.dart
 0s json_serializable on 40 inputs: 40 skipped
 0s source_gen:combining_builder on 40 inputs; lib/feature/dashboard/domain/model/dashboard_tab.dart
 0s source_gen:combining_builder on 40 inputs: 40 skipped
 0s flutter_gen_runner on 1 input; $package$
 0s flutter_gen_runner on 1 input: 1 skipped
 Running the post build.
 Writing the asset graph.
E json_serializable on lib/feature/dashboard/presentation/screen/dashboard_screen.dart:
 AssetNotFoundException: sdk|lib/feature/auth/domain/model/auth_result.freezed.dart (/Users/dev/project_root/packages/sdk/lib/feature/auth/domain/model/auth_result.freezed.dart)
E json_serializable on lib/feature/dashboard/presentation/widget/home_tab.dart:
 AssetNotFoundException: sdk|lib/feature/auth/domain/model/authenticated_user.g.dart (/Users/dev/project_root/packages/sdk/lib/feature/auth/domain/model/authenticated_user.g.dart)
E json_serializable on lib/feature/dashboard/presentation/widget/settings_tab.dart:
 AssetNotFoundException: sdk|lib/feature/auth/domain/model/authenticated_user.freezed.dart (/Users/dev/project_root/packages/sdk/lib/feature/auth/domain/model/authenticated_user.freezed.dart)
E json_serializable on lib/feature/splash/presentation/screen/splash_screen.dart:
 AssetNotFoundException: sdk|lib/feature/auth/domain/model/user.g.dart (/Users/dev/project_root/packages/sdk/lib/feature/auth/domain/model/user.g.dart)
E json_serializable on lib/main.dart:
 AssetNotFoundException: sdk|lib/feature/auth/domain/model/user.freezed.dart (/Users/dev/project_root/packages/sdk/lib/feature/auth/domain/model/user.freezed.dart)
E json_serializable on test/widget_test.dart:
 AssetNotFoundException: sdk|lib/feature/auth/domain/model/auth_token.g.dart (/Users/dev/project_root/packages/sdk/lib/feature/auth/domain/model/auth_token.g.dart)
 Failed to build with build_runner in 1s; wrote 0 outputs.

All generated files *.g.dart and *.freezed.dart under project_root exists but it reports AssetNotFoundException.

When I execute script like this:

#!/bin/bash
set -e
echo "Cleaning and building build_runner in sdk..."
melos exec --scope sdk -- flutter pub run build_runner clean
melos exec --scope sdk -- flutter pub run build_runner build --delete-conflicting-outputs
echo "Cleaning and building build_runner in app..."
melos exec --scope app -- flutter pub run build_runner clean
melos exec --scope app -- flutter pub run build_runner build --delete-conflicting-outputs

Then there is no errors like: AssetNotFoundException.

And after this also when I execute: melos run build_runner it finishes with success. I wonder what is the difference between this script above and the melos run build_runner which returns errors.

Can someone put more light on this. I tried to extract the problem to small one but I can't reproduce it in small codebase. Need some ideas where to look or what to check in our large codebase.

asked Sep 5, 2025 at 15:33
1
  • build_runner maintainer here. That's surprising--usually there should be no way to cause an AssetNotFoundException. Since it only happens with melos, I guess it's something to do with how melos works. Maybe try asking them? I wonder if it runs multiple things in parallel; build_runner expects to only be run once in parallel. Commented Sep 8, 2025 at 7:10

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.