AOT snapshot startup failure from unsupported dart:mirrors usage
0 reputation · 10 Jan 2023, 15:35 UTC
0 reputation · 10 Jan 2023, 15:35 UTC
Determine whether a Dart application deployed as an AOT-compiled executable can use dart:mirrors for runtime reflection, or whether reflective code must be replaced with build-time code generation before the snapshot is produced.
AOT snapshots do not support dart:mirrors, while JIT mode does. Deployment failures may appear as VM or snapshot errors on stderr without original source line numbers. Exact support boundaries differ between Dart 2.x and Dart 3.x releases and require confirmation against the installed SDK changelog.
dart:mirrors cause a compile-time rejection or a runtime failure in an AOT snapshot?dart:mirrors as unsupported in AOT output?No. A Dart application deployed as an AOT-compiled executable cannot use dart:mirrors for runtime reflection. Reflective code must be replaced with build-time code generation before the snapshot is produced. dart:mirrors works under JIT (dart run) but is rejected by the AOT snapshot toolchain.
Likely explanation: Your deployment pipeline compiles the application to an AOT snapshot (Dart 3: dart compile exe; Dart 2: dart2native), and the snapshot toolchain encounters a dart:mirrors import or mirror API call. Because AOT snapshots do not support reflection, snapshot generation fails, or the produced snapshot aborts at startup with a VM/snapshot error on stderr. Original source line numbers are often unavailable in that output.
Confirmed facts:
dart:mirrors; JIT mode does.Version assumption: Dart 2.x stable AOT and Dart 3.x stable AOT both treat dart:mirrors as unsupported. Exact version boundaries and error text are not verified here; confirm them against your installed SDK changelog using dart --version.
grep -R "dart:mirrors" . --include="*.dart"
build_runner or equivalent) before snapshotting.dart:mirrors imports.# Dart 3.x
dart compile exe bin/your_app.dart -o build/your_app
# Dart 2.x
dart2native bin/your_app.dart -o build/your_app
dart --version and check the SDK changelog for AOT and dart:mirrors support statements.dart:mirrors and run dart compile exe (or dart2native) against it to confirm snapshot generation fails before deploying changes.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.