"Value at position 4 in the NgModule.imports of MyCommonLibraryModule is not a reference" when importing an Angular 9 library
As per the documents https://update.angular.io/#8.0:9.0 we you should import deeply from the specific component
import {MatAutocompleteModule} from '@angular/material/autocomplete';
@NgModule({
imports: [
MatAutocompleteModule
]
Related videos on Youtube
adamdport
I'm obsessed with disc golf, have pet chickens, and 3D print whatever I can
Updated on June 04, 2022Comments
-
adamdport almost 2 years
I have two Angular projects that share common code through an Angular library. I ran
ng update
in both projects and my Angular library to try to upgrade from Angular 8 to 9. The migration scripts changed mytsconfig.app.json
file from"include": [ "../src/**/*" ]
to
"files": [ "main.ts", "polyfills.ts" ], "include": [ "src/**/*.d.ts" ]
Angular's migration guide states
We have updated the tsconfig.app.json to limit the files compiled. If you rely on other files being included in the compilation, such as a typings.d.ts file, you need to manually add it to the compilation.
When I tried to run my app (
ng serve
from one of the projects that consumes the library), I got an errorERROR in Failed to compile entry-point my-common-library (module as esm5) due to compilation errors: node_modules/my-common-library/fesm5/my-common-library.js:5207:30 - error NG1010: Value at position 4 in the NgModule.imports of MyCommonLibraryModule is not a reference: [object Object] 5207 imports: [ ~ 5208 CommonModule, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... 5225 MatAutocompleteModule ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5226 ], ~~~~~~~~~~~~~~~~~~~~~
If I replace my library's
tsconfig.app.json
back to"include": [ "../src/**/*" ]
then everything works great. So I guess my questions are
- Is
ng update
not meant to work with libraries? - Is this a bug?
- Is my "fix" OK or am I missing out on some Angular 9 optimizations? Is there a better way?
-
Lincoln Alves about 4 yearsI'm also having the same problem here. I work with an application and a shared library. But in my case, even this tsconfig.app.json fix didn't work...
-
Viszman about 4 years@adamdport can you paste contents of app.module.ts?
-
Ricardo Fornes almost 4 yearsI'm having the same issue and reverting tsconfig.app.json didn't fixed it for me
-
Ricardo Fornes almost 4 yearsBelow answer did it for me - the first warning is very clear, the code contains deep imports. Fixed across code and now error is gone.
- Is
-
Ricardo Fornes almost 4 yearsThank you, this did it for me.