Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't build_runner generate files when serializing JSON in dart/flutter

I'm just trying to generate my files with the same command i stored like 3 months ago (i'm not very good with backend and devops) and now it doesn't generate the files anymore. It tells me to use the delete command which i don't remember but even using that one my files still won't be generated. This is what my log looks like, and below you can find the code for a simple class.

One of my guesses would be this has something to do with me changing my github account, since there's the permission issue mentioned.

Im using vs code in windows 10.

log file:

E:\1 Work\flutter_pilot> flutter pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 336ms

[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 12.5s

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 787ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Found 13 declared outputs which already exist on disk. This is likely because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository.
[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them. These outputs must be removed manually or the build can be run with `--delete-conflicting-outputs`. The outputs are: lib/models/advisory-service-item.g.dart
lib/models/advisory-service.g.dart
lib/models/auth.g.dart
lib/models/contract.g.dart
lib/models/contributor.g.dart
lib/models/exact-cost-values.g.dart
lib/models/exact-cost.g.dart
lib/models/expert.g.dart
lib/models/paginator-info.g.dart
lib/models/person.g.dart
lib/models/project.g.dart
lib/models/system-country.g.dart
lib/models/user.g.dart
pub failed (78)

class file:

import 'package:json_annotation/json_annotation.dart';
part 'organisation.g.dart';

@JsonSerializable()
class Organisation {
  final String name;
  Organisation({this.name});

  factory Organisation.fromJson(Map<String, dynamic> json) => _$OrganisationFromJson(json);

  Map<String, dynamic> toJson() => _$OrganisationToJson(this);
}
like image 952
morgred Avatar asked Jan 09 '20 16:01

morgred


3 Answers

I had a similar issue, but I am using Android Studio IDE and I have done the following step:

File => Invalidate caches / Restart

Run following command:

flutter clean

flutter pub get

flutter packages pub run build_runner build --delete-conflicting-outputs  
     

About --delete-conflicting-outputs

Assume conflicting outputs in the users package are from previous builds, and skip the user prompt that would usually be provided.

Reference

like image 114
Dharmesh Mansata Avatar answered Sep 23 '22 17:09

Dharmesh Mansata


If you read the error message carefully, you'll see that it's asking you to try adding --delete-conflicting-outputs at the end of your command. So you should try flutter packages pub run build_runner build --delete-conflicting-outputs.

like image 37
Rick Avatar answered Sep 20 '22 17:09

Rick


You just run bellow code..

flutter pub run build_runner build --delete-conflicting-outputs
like image 9
Enamul Haque Avatar answered Sep 20 '22 17:09

Enamul Haque