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

import 'package:realm/realm.dart';

part 'RealmModels.g.dart';

class _Chatroom {
  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.

Hi @Desislava_St_Stefanova, I have the same problem:

when I try to generate the RealmObject Class with the command flutter pub run realm generate I received this error:

Unhandled exception:
ProcessException: No such file or directory
  Command: dart run build_runner build --delete-conflicting-outputs
#0      _ProcessImpl._start (dart:io-patch/process_patch.dart:401:33)
#1      Process.start (dart:io-patch/process_patch.dart:38:20)
#2 (package:realm/src/cli/generate/generate_command.dart:41:35)
#3      CommandRunner.runCommand (package:args/command_runner.dart:209:27)
#4<anonymous closure> (package:args/command_runner.dart:119:25)
#5      new Future.sync (dart:async/future.dart:302:31)
#6 (package:args/command_runner.dart:119:14)
#7      main (package:realm/src/cli/main.dart:40:7)
#8      main (file:///Users/***/flutter/.pub-cache/hosted/
#9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
pub finished with exit code 255

This is the class that I want to generate the RealmObjectClass:

import 'package:realm/realm.dart';

part 'schemas.g.dart';

class _Item {
  late ObjectId id;
  bool isComplete = false;
  late String summary;
  late String ownerId;

My configuration is:

realm: ^0.8.0+rc
Flutter version 3.3.8
Dart version 2.18.4
DevTools version 2.15.0

I tried both with the test app that provides Realm and on a new project.
Thank for your help!

Hi @Omar_Quattrin ,
welcome to MongoDB forum!
This error happened on my environment only when I had already a generated file and I tried to change the model and to regenerate. But after I deleted the old file I was able to generate the new model.
But it seems that you received that error even in a new project on your first generate.
Did you have the same issue like @Shawn_L1 running pod install?
Could you share some more details about your environment and the commands that you run?
Thank you!

1 Like

Hi @Desislava_St_Stefanova thank you for the answer.
Yes, I’m receiving the error even in a new project on my first generate.
I tried to running pod install (I hadn’t opened the iOS project yet) but if I try to rerun the command I received the same error.

I’m using Android Studio (Dolphin | 2021.3.1 Patch 1) on Mac with macOS Monterey (version 12.6) and the following configuration of flutter:

[✓] Flutter (Channel stable, 3.3.8, on macOS 12.6 21G115 darwin-x64, locale it)
    • Flutter version 3.3.8 on channel stable at /Users/***/flutter
    • Upstream repository
    • Framework revision 52b3dc25f6 (3 weeks ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/***/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio
    • Flutter plugin can be installed from:
    • Dart plugin can be installed from:
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

The command that 'm unsing for generate the RealmObject is:

flutter pub run realm generate

and the error I’m getting is:

Unhandled exception:
ProcessException: No such file or directory
  Command: dart run build_runner build --delete-conflicting-outputs
#0      _ProcessImpl._start (dart:io-patch/process_patch.dart:401:33)
#1      Process.start (dart:io-patch/process_patch.dart:38:20)
#2 (package:realm/src/cli/generate/generate_command.dart:41:35)
#3      CommandRunner.runCommand (package:args/command_runner.dart:209:27)
#4<anonymous closure> (package:args/command_runner.dart:119:25)
#5      new Future.sync (dart:async/future.dart:302:31)
#6 (package:args/command_runner.dart:119:14)
#7      main (package:realm/src/cli/main.dart:40:7)
#8      main (file:///Users/***/flutter/.pub-cache/hosted/
#9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
pub finished with exit code 255

Thanks for your help!

Did pod install command completed successfully on your environment?
Did you follow this thread Unable to install on iOS? It is a different issue, but they might be related.

Yes, I had the problem described in this thread when I used the command pod install

Unable to install vendored xcframework `realm_dart` for Pod `realm`, because it contains both static and dynamic frameworks.

but I resolved this, instead my problem remained. :frowning:

I had also try to use Visual Studio Code instead Android Studio but no difference.

Did you try:
flutter clean
flutter pub get
and then to generate?

Hi, same for me too.
I thought I solved it by successfully installing the package, but I still couldn’t successfully run flutter pub run realm generate.

For me, I tried running flutter clean and flutter pub get multiple times, but no luck.
+Fyi, there was no .g.dart file in the expected location, so that wouldn’t have caused the issue.

Unfortunately, I can’t reproduce this problem.
We will continue the investigation.
Meanwhile could you please try:
flutter pub add build_runner
flutter pub run build_runner build --delete-conflicting-outputs

Solution for this is to remove generate: true in flutter section in pub spec.yaml it will work @Shawn_L1 @Omar_Quattrin

1 Like

I tried to make

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

and this is the result:

% **flutter pub add build_runner**
Resolving dependencies...
  _fe_analyzer_shared 47.0.0 (50.0.0 available)
  analyzer 4.7.0 (5.2.0 available)
  async 2.9.0 (2.10.0 available)
  boolean_selector 2.1.0 (2.1.1 available)
  build_resolvers 2.0.10 (2.1.0 available)
  collection 1.16.0 (1.17.0 available)
  matcher 0.12.12 (0.12.13 available)
  material_color_utilities 0.1.5 (0.2.0 available)
  source_span 1.9.0 (1.9.1 available)
  stack_trace 1.10.0 (1.11.0 available)
  stream_channel 2.1.0 (2.1.1 available)
  string_scanner 1.1.1 (1.2.0 available)
  test_api 0.4.12 (0.4.16 available)
  vector_math 2.1.2 (2.1.4 available)
Got dependencies!

% **flutter pub run build_runner build --delete-conflicting-outputs**
[INFO] Generating build script...
[INFO] Generating build script completed, took 480ms

[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 7.7s

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

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms

[INFO] Running build...
[INFO] Generating SDK summary...
[INFO] 2.4s elapsed, 0/3 actions completed.
[INFO] 4.3s elapsed, 0/3 actions completed.
[INFO] Generating SDK summary completed, took 5.1s

[INFO] 6.2s elapsed, 0/3 actions completed.
[INFO] 7.3s elapsed, 0/3 actions completed.
[INFO] 8.3s elapsed, 0/3 actions completed.
[INFO] 15.2s elapsed, 0/3 actions completed.
[WARNING] No actions completed for 15.2s, waiting on:
  - realm:realm_generator on lib/schemas.dart
  - realm:realm_generator on lib/main.dart
  - realm:realm_generator on test/widget_test.dart

[INFO] 16.2s elapsed, 0/3 actions completed.
[INFO] realm:realm_generator on lib/main.dart:[generate (0)] completed, took 1.6s
[INFO] realm:realm_generator on test/widget_test.dart:[generate (0)] completed, took 67ms
[INFO] realm:realm_generator on lib/schemas.dart:[generate (0)] completed, took 87ms
[INFO] Running build completed, took 17.2s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 36ms

[INFO] Succeeded after 17.3s with 2 outputs (7 actions)

After that I tried to running flutter pub run realm generate and I got the same error.

1 Like

Hi @Oleksii_Moisieienko in my pubspec.yaml I don’t find generate:true in the flutter section

name: new_app
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to

version: 1.0.0+1

  sdk: '>=2.18.5 <3.0.0'

    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  realm: ^0.8.0+rc
  build_runner: ^2.3.2

    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page:

# The following section is specific to Flutter packages.

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

So @Omar_Quattrin you have already the models generated, right? As I see the output “Succeeded after 17.3s with 2 outputs” - your .g.dart files must be there.
You can use flutter pub run build_runner build as a workaround for now.
We will try to figure out the issue with flutter pub run realm generate for some of the next releases.
@Shawn_L1 does this work for you flutter pub run build_runner build?

YES!! The file .g.dart was generated with flutter pub run build_runner build !

Thank you


It worked for me too! Thanks


Hi again after long time.
Since flutter pub run command has been deprecated, for further generating realm models you can use the following command:

  • For Realm Dart SDK: dart run realm_dart generate
  • For Realm Flutter SDK: dart run realm generate
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.