Angular 9: Value at position X in the NgModule.imports is not a reference

前端 未结 4 2023
轻奢々
轻奢々 2021-01-18 03:40

I upgraded an Angular App from v8 to v9. The project imports a custom UI library using Angular 8 and moment.js.

When I build it:

  1. It genera
相关标签:
4条回答
  • 2021-01-18 04:10

    In my case the issue was related to an imported library, that was not Angular v9 compatible (among other things it was not using deep links to Angular Material and moment.js).

    I was lucky as the library is an intern one and I could fix these points and republish it. After that it built without any problems or changes in my project.

    0 讨论(0)
  • 2021-01-18 04:14

    #2 happened to me after I accidentally used npm link in a project's folder instead of it's dist folder.

    0 讨论(0)
  • 2021-01-18 04:19

    you need to change your custom build of modules, so you need to make analog changes to the ones below, in my case i needed to change:

    export class ThemeModule {
      static forRoot(): ModuleWithProviders {
        return <ModuleWithProviders>{
          ngModule: ThemeModule,
          providers: [
            ...NbThemeModule.forRoot(
              {
                name: 'default',
              },
              [DEFAULT_THEME, COSMIC_THEME, CORPORATE_THEME, DARK_THEME],
            ).providers,
          ],
        };
      }
    }
    

    to:

    export class ThemeModule {
      static forRoot(): ModuleWithProviders<ThemeModule> {
        return {
          ngModule: ThemeModule,
          providers: [
            ...NbThemeModule.forRoot(
              {
                name: 'default',
              },
              [DEFAULT_THEME, COSMIC_THEME, CORPORATE_THEME, DARK_THEME],
            ).providers,
          ],
        };
      }
    }
    
    0 讨论(0)
  • 2021-01-18 04:19

    In my case, I think there were some incompatibilities between some of the angular libraries that were imported. I think I previously manually bumped @angular/material to 9.2.3 without bumping the other angular libraries.

    When I created a new repository using: ng new test-ng9 and then added angular material ng add @angular/material, there were no compilation issues.

    So I took the dependencies that the angular cli included in the temp repo and replaced the ones in my existing repository. Then it worked fine.

    Before:

        "@angular/animations": "~9.1.6",
        "@angular/cdk": "9.1.1",
        "@angular/common": "~9.1.1",
        "@angular/compiler": "~9.1.1",  
        "@angular/core": "~9.1.1",
        "@angular/forms": "~9.1.1",
        "@angular/material": "9.2.3",
        "@angular/platform-browser": "~9.1.1",
        "@angular/platform-browser-dynamic": "~9.1.1",
        "@angular/router": "~9.1.1",
    

    After:

        "@angular/animations": "~9.1.6",
        "@angular/cdk": "9.1.1",    
        "@angular/common": "~9.1.6",
        "@angular/compiler": "~9.1.6",
        "@angular/core": "~9.1.6",
        "@angular/forms": "~9.1.6",
        "@angular/material": "^9.2.4",
        "@angular/platform-browser": "~9.1.6",
        "@angular/platform-browser-dynamic": "~9.1.6",
        "@angular/router": "~9.1.6",
    
    0 讨论(0)
提交回复
热议问题