Why is Module.DEFAULT_REFLECTOR not initialized?

Issue

This is an Angular 1.0 application. The error in Chrome’s console is:

Uncaught Module.DEFAULT_REFLECTOR not initialized for dependency injection.http://goo.gl/XFXx9G

I’ve read the other posts, and I do have the Angular transformer in my pubspec.yaml:

dependencies:
  barback: any
  browser: any
  angular: 1.0.0
  msgpack:
    git:
      url: git://github.com/danellis/dart-msgpack.git
      ref: master
dev_dependencies:
  template_cache_transformer: any
threadsafe: yes
transformers:
  - $dart2js:
      environment:
        MIRRORS: 'false'
  - angular:
      html_files:
        - lib/templates/app.html
        - lib/templates/input.html
        - lib/templates/roster.html
        - lib/templates/space.html
        - lib/templates/space_list.html
        - lib/templates/alerts.html
        - lib/templates/rostermenu.html
  - template_cache_transformer:
      entry_point: webatara|templates/app.html

My main function looks like this:

void main() {
    applicationFactory().addModule(new WebataraModule()).run();
}

After a pub build, the modified main.dart has this in it:

void main() {
  setStaticReflectorAsDefault();
    staticApplicationFactory(generated_static_metadata.typeAnnotations, generated_static_expressions.getters, generated_static_expressions.setters, generated_static_expressions.symbols, generated_static_type_to_uri_mapper.typeToUriMapper).addModule(new WebataraModule()).run();
}

setStaticReflectorAsDefault does this:

setStaticReflectorAsDefault() => Module.DEFAULT_REFLECTOR = new GeneratedTypeFactories(typeFactories, parameterKeys);

So it would seem that Module.DEFAULT_REFLECTOR does get set. So why the error?

Solution

The transformers are applied in the order listed in the transformers section. $dart2js should always be the last and template_cache_transformer should probably come before angular.

Answered By – Günter Zöchbauer

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *