Skip to content
This repository has been archived by the owner on Dec 6, 2017. It is now read-only.

Transform InjectorGenerator No Element #162

Open
jrote1 opened this issue Aug 8, 2014 · 10 comments · May be fixed by #202
Open

Transform InjectorGenerator No Element #162

jrote1 opened this issue Aug 8, 2014 · 10 comments · May be fixed by #202

Comments

@jrote1
Copy link

jrote1 commented Aug 8, 2014

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

@vicb
Copy link
Contributor

vicb commented Aug 8, 2014

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 ?

@antingshen
Copy link
Contributor

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.

@Pajn
Copy link

Pajn commented Aug 26, 2014

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.

@jarredkenny
Copy link

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?

@MikeMitterer
Copy link

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

@zoechi
Copy link

zoechi commented Dec 10, 2014

@jarredkenny To the entry page for example

@MikeMitterer
Copy link

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

@seguins
Copy link

seguins commented Dec 19, 2014

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 seguins linked a pull request Jan 8, 2015 that will close this issue
@MikeMitterer
Copy link

@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...

@seguins
Copy link

seguins commented Jan 25, 2015

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 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

8 participants