dotansimha / dotansimha/graphql-code-generator
build_runner can't compile its build script because Amplify pulls in native-asset/"build hooks" packages (sqlite3/jni)
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
build_runner can't compile its build script because Amplify pulls in native-asset/"build hooks" packages (sqlite3/jni), and that combination is currently broken in Dart's tooling (dart-lang/native#2792).
This is a known structural conflict between Dart's newer Native Assets (Build Hooks) feature and how build_runner compiles its isolated build scripts.Because build_runner uses dart compile under the hood to compile your build script (.dart_tool/build/entrypoint/build.dart) into an AOT snapshot, it triggers a hard failure when a package like AWS Amplify introduces transitive dependencies (sqlite3, jni) that declare Native Assets build hooks. Currently, dart compile completely blocks compilation if any dependency in the tree uses build hooks.Until the underlying issue in Dart's native toolchain (dart-lang/native#[2](https://github.com/Baseflow/flutter_cached_network_image/issues/1031)792) is patched, you can use these workarounds to unblock your code generation:
I found a couple of solutions, but is there a main solution?
Workaround 1: Force JIT Compilation (Bypass AOT Snapshotting)You can force build_runner to run using the Dart VM in JIT mode rather than attempting to compile the entrypoint script into an AOT executable.Run build_runner with the --no-precompile flag:
Workaround 2: Downgrade Packages to Pre-Native-Asset VersionsIf you do not want to change your build commands, you can temporarily downgrade the transitive packages to versions released before they adopted Native Assets build hooks.Add explicit dependency_overrides in your pubspec.yaml to pin sqlite3 and jni down to versions that do not utilize hook/build.dart:
Workaround 3: Decouple Build Tools into a Local Package SplitIf neither of the above works comfortably for your workflow, separate your code-generation tools (like freezed, json_serializable) from your main application. You can isolate a smaller local Dart package that holds your data models and code generation dependencies, ensuring Amplify is never pulled into that package's dependency tree.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.