Latest builds from Angular2 complain with: NgModule DynamicModule uses HomeComponent via “entryComponents”

后端 未结 5 1140
一整个雨季
一整个雨季 2021-01-01 11:12

Since switching to the latest builds of Angular 2 (i.e. on github, master), I get warnings as follows about all my components:

NgModule DynamicModule

5条回答
  •  心在旅途
    2021-01-01 11:38

    There's one other thing to be careful of with regard to this warning.

    I was receiving it even though I was in fact declaring the component in my module and it was driving me up the wall because everything looked to be correct.

    So I stepped through compiler.umd.js where the warning was getting generated and I noticed that the component for which I was getting the error was being added to the array of directives twice here:

     if (force || !transitiveModule.directivesSet.has(dirMeta.type.runtime)) {
                transitiveModule.directivesSet.add(dirMeta.type.runtime);
                transitiveModule.directives.push(dirMeta);
                declaredDirectives.push(dirMeta);
                this._addTypeToModule(dirMeta.type.runtime, moduleType);
                return true;
            }
    

    Basically, even though the component was already in directivesSet, transitiveModule.directivesSet.has(dirMeta.type.runtime) was evaluating to false so it was getting added again and one of these was causing the warning to appear.

    It turned out that the import statements in my routing file and my module file were slightly different. One capitalized the first letter of a directory in the path, whereas in the other the directory was in all lowercase like so:

    //in routing
    import { SomeComponent } from './Directory/some.component';
    
    //in app module
    import { SomeComponent } from './directory/some.component';
    

    Once I changed so the paths matched, the warning went away. Everything else seemed to function properly with the mismatched casing.

提交回复
热议问题