di.dart icon indicating copy to clipboard operation
di.dart copied to clipboard

Transform InjectorGenerator No Element

Open jrote1 opened this issue 11 years ago • 10 comments

In Version 2 the transformer now requires that all my libraries need to have a main method.

Why is this required / is this a bug

jrote1 avatar Aug 08 '14 16:08 jrote1

DI2 is used by angular and a lot of its libs do not have a main function, could you please provided a quick repro case ?

vicb avatar Aug 08 '14 16:08 vicb

It requires a main method so it can insert code to initialize DI at the top of the main function. If your library is to be used by other libraries, you can do what Angular does and call the DI transformer in its transformer. Then apps with a main method will list Angular as a transformer which will call DI, so it avoids Angular itself running the DI transformer without a main method.

antingshen avatar Aug 08 '14 16:08 antingshen

If I don't have a main method the di transformer (run by angulars transformer) throws this:

Build error:
Transform InjectorGenerator on raxa|web/lib/raxa.dart threw error: Bad state: No element
dart:collection/iterable.dart 319                                              IterableBase.first
http://localhost:41984/packages/di/transformer/injector_generator.dart 377:10  _Processor._editMain
http://localhost:41984/packages/di/transformer/injector_generator.dart 73:14   _Processor.process
http://localhost:41984/packages/di/transformer/injector_generator.dart 25:59   InjectorGenerator.applyResolver
http://localhost:41984/packages/code_transformers/src/resolvers.dart 113:44    Transformer&ResolverTransformer.applyToEntryPoints.<fn>.<fn>
dart:async/future.dart 118                                                     Future.Future.<fn>
dart:async-patch/timer_patch.dart 12                                           Timer._createTimer.<fn>
dart:io/timer_impl.dart 292                                                    _handleTimeout
dart:isolate-patch/isolate_patch.dart 122                                      _RawReceivePortImpl._handleMessage

dart:collection                                                                IterableBase.first
http://localhost:41984/packages/di/transformer/injector_generator.dart 377:10  _Processor._editMain
http://localhost:41984/packages/di/transformer/injector_generator.dart 73:14   _Processor.process
http://localhost:41984/packages/di/transformer/injector_generator.dart 25:59   InjectorGenerator.applyResolver
http://localhost:41984/packages/code_transformers/src/resolvers.dart 113:44    Transformer&ResolverTransformer.applyToEntryPoints.<fn>.<fn>
dart:isolate                                                                   _RawReceivePortImpl._handleMessage

[Error from _Serial on raxa|web/main.dart]:
Could not load asset raxa|web/lib/raxa.dart
[Error from _Serial on raxa|web/main.dart]:
Could not load asset raxa|web/lib/raxa.dart

With this main method: main() {} everything works as expected.

Pajn avatar Aug 26 '14 15:08 Pajn

I just updated my copy of the Dart SDK to 1.7.2 and am now receiving the same error. Where does the main method need to be added?

jarredkenny avatar Nov 03 '14 15:11 jarredkenny

OMG!!!!

The same here. Get tons of errors like the one above.

Here is my sample (I'm using Dart 1.8.3 + Angular 1.0)

[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/angular/tools/template_cache_generator.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Decorator
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/angular/tools/template_cache_generator.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Component
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/angular/tools/template_cache_generator.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Formatter
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/angular/tools/template_cache_generator.dart]:
Unable to resolve injected type name perf_api.Profiler
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/analyzer/formatter.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Decorator
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/analyzer/formatter.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Component
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/analyzer/formatter.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Formatter
[Warning from InjectorGenerator on mobiad_rest_ui|example/garage/packages/analyzer/formatter.dart]:
Unable to resolve injected type name perf_api.Profiler
Build error:
Transform InjectorGenerator on mobiad_rest_ui|example/garage/packages/analyzer/formatter.dart threw error: Bad state: No element
dart:collection/iterable.dart 327                      IterableBase.last
package:di/transformer/injector_generator.dart 368:30  _Processor._editMain
package:di/transformer/injector_generator.dart 72:14   _Processor.process
package:di/transformer/injector_generator.dart 25:59   InjectorGenerator.applyResolver
package:code_transformers/src/resolvers.dart 113:44    Transformer&ResolverTransformer.applyToEntryPoints.<fn>.<fn>
dart:async/future.dart 118                             Future.Future.<fn>
dart:async-patch/timer_patch.dart 12                   Timer._createTimer.<fn>
dart:io/timer_impl.dart 292                            _handleTimeout
dart:isolate-patch/isolate_patch.dart 130              _RawReceivePortImpl._handleMessage

dart:collection                                        IterableBase.last
package:di/transformer/injector_generator.dart 368:30  _Processor._editMain
package:di/transformer/injector_generator.dart 72:14   _Processor.process
package:di/transformer/injector_generator.dart 25:59   InjectorGenerator.applyResolver
package:code_transformers/src/resolvers.dart 113:44    Transformer&ResolverTransformer.applyToEntryPoints.<fn>.<fn>
dart:isolate                                           _RawReceivePortImpl._handleMessage

MikeMitterer avatar Dec 10 '14 13:12 MikeMitterer

@jarredkenny To the entry page for example

zoechi avatar Dec 10 '14 17:12 zoechi

I found out that it only occures if the source is not in /web In my case it was /examples/garage moving the source over to /web the errors disappeared

MikeMitterer avatar Dec 10 '14 21:12 MikeMitterer

Same error even if my source are all in /web. I created a small sample test : https://gist.github.com/seguins/f04dd4806a426dd45b72 If I comment the import of my library, it works. I'm using dart 1.8.3 on Windows 8 x64.

seguins avatar Dec 19 '14 15:12 seguins

@seguins I tried it with your patch and AD 1.1 - still the same.

One of my samples is in

example/mm_uia_overlay/
  packages
  index.html
  main.dart

If I

pub build example/mm_uia_overlay

I get a ton of errors like:

Build error:
Transform HtmlDartReferencesGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/logging_handlers/src/browser/logviewer.html emitted logging_handlers|lib/src/browser/logviewer.dart.html_reference, which wasn't in the same package (webapp_base_ui_angular).
Build error:
Transform HtmlDartReferencesGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/logging_handlers/src/client/loggerui.html emitted logging_handlers|lib/src/client/loggerui.dart.html_reference, which wasn't in the same package (webapp_base_ui_angular).
[Warning from InjectorGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/di/src/mirrors.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Decorator
[Warning from InjectorGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/di/src/mirrors.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Component
[Warning from InjectorGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/di/src/mirrors.dart]:
Unable to resolve injectable annotation angular.core.annotation_src.Formatter
[Warning from InjectorGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/di/src/mirrors.dart]:
Unable to resolve injected type name perf_api.Profiler
Build error:
Transform InjectorGenerator on webapp_base_ui_angular|example/mm_uia_overlay/packages/di/src/mirrors.dart threw error: Bad state: No element
dart:collection/iterable.dart 319                      IterableBase.first
package:di/transformer/injector_generator.dart 374:10  _Processor._editMain
package:di/transformer/injector_generator.dart 72:14   _Processor.process
package:di/transformer/injector_generator.dart 25:59   InjectorGenerator.applyResolver
package:code_transformers/src/resolvers.dart 113:44    Transformer&ResolverTransformer.applyToEntryPoints.<fn>.<fn>
dart:async/future.dart 118                             Future.Future.<fn>
...

BUT!!!! If I

ln -s example/mm_uia_overlay web
pub build web

It works...

MikeMitterer avatar Jan 24 '15 18:01 MikeMitterer

It's strange because, you have an error at line 374 of package:di/transformer/injector_generator.dart and in my file, there is nothing at the line : https://github.com/seguins/di.dart/blob/no_main/lib/transformer/injector_generator.dart#L374

Maybe there is a kind of cache ?

seguins avatar Jan 25 '15 17:01 seguins