Keep failing to generate RealmModel

Hi, I’m trying to generate a RealmModel by following this guide.
I ran flutter pub run realm generate, but it fails with an error pub finished with exit code 255.
I do not see any more logs nor stacktrace. Do you know what code 255 stands for and how i can fix it?


Ran on: M1 Macbook | Flutter 3.3.8 | Dart 2.18.4 | realm ^0.7.0+rc
What I’ve done:

  • Restart the terminal
  • Restart the computer
  • Update macOS to the latest one (13.0.1)
  • Update Flutter and Dart to the latest one (Flutter 3.3.8, Dart 2.18.4)

Repro Steps

  1. Add the code snippet below (RealmModels.dart) to a flutter project
  2. Run flutter pub run realm generate
  3. I get an error pub finished with exit code 255

Code Snippet
/lib/Functions/Realm/RealmModels.dart

import 'package:realm/realm.dart';

part 'RealmModels.g.dart';

@RealmModel()
class _Chatroom {
  @PrimaryKey()
  late final String id;

  late List<String> users;
}

There’s a red line under part 'RealmModels.g.dart';, which says “Target of URI hasn’t been generated: ‘‘RealmModels.g.dart’’. Try running the generator that will generate the file referenced by the URI.”

Relevant Log Output
% flutter pub run realm generate
pub finished with exit code 255

Hi @Shawn_L1 ,
Thank you for interest to realm package!
To solve the issue, please make sure you have deleted manually your generated file RealmModels.g.dart.
Then run flutter pub run realm generate --clean.
Now, try again flutter pub run realm generate.
Please, let me know if this help!

Hi @Desislava_St_Stefanova , thank you for your interest in my issue!
I’m facing a new issue ([Bug]: Unable to install on iOS · Issue #1023 · realm/realm-dart · GitHub) which makes me unable to install realm on iOS. I think this issue would be solved if I solve that one.
I’ll come back if I still face the issue after solving that one.
Thank you

I managed to reproduce this issue when I was using XCode and the external terminal. Maybe the generated file is somehow locked when it is used by different processes. That’s why you have to remove it manually.