Json_serializable.dart: Invalid argument(s): Path must be absolute : dart:core

Created on 20 Sep 2019  路  6Comments  路  Source: google/json_serializable.dart

Doing the most basic json serializable stuff that's always worked on other projects.

I didn't change anything, simply came back to the project the day and encountered this error.

My user

import 'package:json_annotation/json_annotation.dart';

part 'user_v1.g.dart';

@JsonSerializable()
class UserV1 {
  String uid;

  /// Optional
  String profilePhotoUrl;
  String username;
  String createdISO;
  bool isBanned;
  bool isDeleted;
  bool isSubscribed;

  UserV1();

  factory UserV1.fromJson(Map<String, dynamic> json) => _$UserV1FromJson(json);
  Map<String, dynamic> toJson() => _$UserV1ToJson(this);
}

build.yaml (root, I had to introduce this because it was trying to parse all the files in lib)

targets:
  $default:
    builders:
      json_serializable:
        options:
          any_map: false
          nullable: true
        generate_for:
          include:
          - lib/models/*

My packages

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2
  simple_animations: ^1.3.3
  redux: ^3.0.0
  redux_persist: ^0.8.2
  flutter_storage: ^0.9.4
  path_provider: ^1.3.0
  shared_preferences: ^0.5.3+4
  flare_flutter: ^1.5.1
  json_annotation: ^3.0.0
  firebase_core: ^0.4.0+9
  firebase_auth: ^0.11.1+3
  cloud_firestore: ^0.12.9+4
  cloud_functions: ^0.4.1+1

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^1.7.0
  json_serializable: ^3.2.2

The error

[INFO] Running build...
[SEVERE] json_serializable:json_serializable on lib/models/user_v1.dart:

Invalid argument(s): Path must be absolute : dart:core
[INFO] Running build completed, took 217ms

I tried deleting flutter, clearing the packages cache, build cache and much more. Nothing works.. at a dead end for hours..

Most helpful comment

I also think that it's not an issue with this package but rather with the analyzer package. The error is not raised with this pubspec.yaml:

analyzer: 0.38.2 # The error is raised if you use directly or transitively v0.38.3
json_annotation: ^3.0.0
json_serializable: ^3.2.2

Cf. dart-lang/sdk#38499

All 6 comments

I'm also having this problem.
Downgrading to 3.0.0 (fixed) solved for me.

Yes downgrading worked, make sure you change your lock file for anyone else reading.

Same issue here. Fixed the error by using:

json_annotation: ^3.0.0
json_serializable: 3.2.0 # Not using the caret symbol

Getting the sam error using hive and hive_generator, so this issue is probably not library-specific.
Downgrading didn't help either, so I created an issue in the dart-lang/build repo.

I also think that it's not an issue with this package but rather with the analyzer package. The error is not raised with this pubspec.yaml:

analyzer: 0.38.2 # The error is raised if you use directly or transitively v0.38.3
json_annotation: ^3.0.0
json_serializable: ^3.2.2

Cf. dart-lang/sdk#38499

I believe this is fixed w/ the latest pkg:analyzer

Was this page helpful?
0 / 5 - 0 ratings