Skip to content
This repository has been archived by the owner on May 20, 2019. It is now read-only.

Angular 4.0.3 #19

Open
lilletech opened this issue Apr 26, 2017 · 12 comments
Open

Angular 4.0.3 #19

lilletech opened this issue Apr 26, 2017 · 12 comments

Comments

@lilletech
Copy link

Hello, I'm using the DynamicComponentModule
It works fine in dev mode but it doesn't work in prod mode (--prod).

I get the error in the browser console :

ERROR Error: Unexpected value 't' imported by the module 't'. Please add a @NgModule annotation.

Here is how i bootstrap the app: (i'm using compiler providers)

...
import { COMPILER_PROVIDERS } from '@angular/compiler';
 platformBrowserDynamic([...COMPILER_PROVIDERS]).bootstrapModule(AppModule)
...

I have a module that contains some components

import { FormTextAreaComponent } from './form-text-area/form-text-area.component';
import { FormSuggestComponent } from './form-suggest/form-suggest.component';
import { FormSelectComponent } from './form-select/form-select.component';
import { FormRadioGroupComponent } from './form-radio-group/form-radio-group.component';
import { FormInputComponent } from './form-input/form-input.component';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

@NgModule({
    imports: [
        CommonModule,
    ],
    declarations: [
        FormInputComponent, FormRadioGroupComponent, FormSelectComponent, FormSuggestComponent, FormTextAreaComponent
    ],
    exports: [
        FormInputComponent, FormRadioGroupComponent, FormSelectComponent, FormSuggestComponent, FormTextAreaComponent
    ]
})
export class FormItemRendererModule { }

And i'm using it in another module

@NgModule({
  imports: [
    HttpModule,
    CommonModule,
    FormEngineComponentRoutingModule,
    FormItemRendererModule,
    DynamicComponentModule.forRoot({
      imports: [FormItemRendererModule]
    })
  ],
  declarations: [TemplateEngineComponent, FormEngineComponent],
})
export class FormEngineModule { }


@lacolaco
Copy link
Owner

Thank you for reporting. unfortunately, I have the same situation, too. I tried to use DynamicComponentModule w/ Angular CLI, but I can't enable --prod yet. #17
In AoT compilation phase of Angular-CLI, something happens. I'm looking for a solution.

@guzuomuse
Copy link

@laco0416 any progress? thanks.

@piotrn1
Copy link

piotrn1 commented May 8, 2017

Try using --no-aot flag for production:
ng build --prod --no-aot

@lilletech
Copy link
Author

With --no-aot, it works but not a real solution.

@douglasward
Copy link

@laco0416 any progress on this yet? Thanks in advance!

@lacolaco
Copy link
Owner

I'm sorry. I don't have any ideas.
Since 4.0, Angular compiler has killed co-existence of AoT compilation and JiT compilation. To use JitCompiler, we have to remove --aot flag.
If someone has a good solution, please let me know it...

@douglasward
Copy link

@gergelybodor
Copy link

Hey, guys! I was able to use DynamicComponentModule with aot build. I don't know if i am missing something, but it went without any complications. I made a repo, check it out.
https://github.com/bgolyoo/test-dynamic-html

I also deployed to github, built with ng build --prod --aot.
https://bgolyoo.github.io/test-dynamic-html/

@maychan111
Copy link

maychan111 commented Jul 26, 2017

@bgolyoo Your project imports CommonModule in DynamicComponentModule.forRoot(). What if it imports a custom module that implements some components needed by the dynamic HTML? In my case, that's when the AOT build fails at runtime with the following error message:

@angular/cli": "1.1.3

vendor.737d505….bundle.js:8 ERROR Error: Unexpected value '[object Object]' imported by the module 'n'. Please add a @NgModule annotation.
    at g (vendor.737d505….bundle.js:859)
    at vendor.737d505….bundle.js:983
    at Array.forEach (<anonymous>)
    at t.getNgModuleMetadata (vendor.737d505….bundle.js:983)
    at t.getNgModuleSummary (vendor.737d505….bundle.js:983)
    at vendor.737d505….bundle.js:983
    at Array.forEach (<anonymous>)
    at t.getNgModuleMetadata (vendor.737d505….bundle.js:983)
    at t._loadModules (vendor.737d505….bundle.js:1004)
    at t._compileModuleAndAllComponents (vendor.737d505….bundle.js:1004)

When I modified my project to import CommonModule instead of the custom module, the AOT build works and no run-time error either, but obviously none of my custom components render in that case.

@gergelybodor
Copy link

@maychan111 Yes, you are right! Upon further inspection I noticed it too.
But in simple cases such as I included, it still works with aot.

@skuby2
Copy link

skuby2 commented Jul 27, 2017

@maychan111 It sounds like we have the same situation. This would be amazing to find a fix for.

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

No branches or pull requests

9 participants