ng-dynamic icon indicating copy to clipboard operation
ng-dynamic copied to clipboard

Angular 4.0.3

Open lilletech opened this issue 8 years ago • 12 comments

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 { }


lilletech avatar Apr 26 '17 13:04 lilletech

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.

lacolaco avatar Apr 27 '17 01:04 lacolaco

@laco0416 any progress? thanks.

guzuomuse avatar May 04 '17 16:05 guzuomuse

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

piotrn1 avatar May 08 '17 16:05 piotrn1

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

lilletech avatar May 09 '17 15:05 lilletech

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

douglasward avatar May 22 '17 14:05 douglasward

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

lacolaco avatar May 23 '17 13:05 lacolaco

@laco0416 does this article help with this at all? https://hackernoon.com/here-is-what-you-need-to-know-about-dynamic-components-in-angular-ac1e96167f9e#3c5c

douglasward avatar Jul 12 '17 14:07 douglasward

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/

gergelybodor avatar Jul 17 '17 22:07 gergelybodor

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

maychan111 avatar Jul 26 '17 05:07 maychan111

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

gergelybodor avatar Jul 26 '17 10:07 gergelybodor

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

skuby2 avatar Jul 27 '17 17:07 skuby2

https://stackoverflow.com/questions/45788613/angular-4-container-element-with-dynamic-content-aot-friendly

gofreddo avatar Oct 20 '17 05:10 gofreddo