xxgreg / mustache

Mustache template Dart library
BSD 2-Clause "Simplified" License
57 stars 59 forks source link

Executed dart2native report error error: import of dart:mirrors is not supported in the current Dart runtime #46

Open nimengbo opened 4 years ago

nimengbo commented 4 years ago
import 'package:mustache/mustache.dart' as mustache;
import 'file_system.dart';

void renderTemplate(String absoluteSourcePath, String finalDestinationPath,
    Map<String, dynamic> context) {
  final sourceFile = fs.file(absoluteSourcePath);
  final templateContents = sourceFile.readAsStringSync();
  final renderedContents =
      mustache.Template(templateContents).renderString(context);

  final finalDestinationFile = fs.file(finalDestinationPath);
  finalDestinationFile.writeAsStringSync(renderedContents);
}

remove mustache import , dart2native can output the bin

xxgreg commented 4 years ago

The library has a hard dependency on dart:mirrors at the moment. This means it's not possible to use with dart2native.

Should be pretty easy for someone to implement a patch.

See: https://github.com/xxgreg/mustache/issues/19#issuecomment-562525727

maks commented 4 years ago

I ran into exactly the same thing trying to do dart2native on dart-sitegen which had a dependency on this package and can confirm that changing over to reflected-mustache fork allows dart2native to compile.