简体   繁体   English

Angular 9:NgModule.imports 中位置 X 的值不是引用

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

I upgraded an Angular App from v8 to v9.我将 Angular 应用程序从 v8 升级到 v9。 The project imports a custom UI library using Angular 8 and moment.js.该项目使用 Angular 8 和 moment.js 导入自定义 UI 库。

When I build it:当我构建它时:

  1. It generates a warning:它会生成警告:
WARNING in Entry point '@myLib/catalogue' contains deep imports into
 '/Users/xyz/Projects/forms-frontend/node_modules/moment/locale/de'.
This is probably not a problem, but may cause the compilation of entry points to be out of order.

In the @myLib/catalogue.js file of the library (inside node_modules folder), the moment.js DE locale is imported as following:在库的@myLib/catalogue.js文件中(在 node_modules 文件夹内),moment.js DE locale 导入如下:

import 'moment/locale/de';


  1. Compilation errors are also triggered:还会触发编译错误:
ERROR in Failed to compile entry-point @myLib/catalogue (es2015 as esm2015) due to compilation errors:
node_modules/@myLib/catalogue/fesm2015/catalogue.js:213:26 - error NG1010: Value at position 2 in the NgModule.imports of FormInputModule is not a reference: [object Object]

213                 imports: [
                             ~
214                     CommonModule,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
219                     TranslateModule
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220                 ],
    ~~~~~~~~~~~~~~~~~

The text of the warning seems explaining exactly the compilation error, where the position (2 in this case) is out of range of the imports array.警告文本似乎准确地解释了编译错误,其中位置(在本例中为 2)超出了导入数组的范围。

I have seen different articles/ github issues about deep-links, but no working solution.我看过关于深层链接的不同文章/ github 问题,但没有有效的解决方案。

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,
      ],
    };
  }
}

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).在我的情况下,问题与导入的库有关,它与 Angular v9 不兼容(除其他外,它没有使用指向 Angular Material 和 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 on my project side.之后,它在我的项目方面没有任何问题或变化。

In my case, I think there were some incompatibilities between some of the angular libraries that were imported.就我而言,我认为导入的一些 angular 库之间存在一些不兼容性。 I think I previously manually bumped @angular/material to 9.2.3 without bumping the other angular libraries.我想我之前手动将@angular/material撞到9.2.3而不撞其他角度库。

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.当我使用以下命令创建新存储库时: ng new test-ng9然后添加角度材料ng add @angular/material ,没有编译问题。

So I took the dependencies that the angular cli included in the temp repo and replaced the ones in my existing repository.因此,我采用了 angular cli 包含在临时存储库中的依赖项,并替换了现有存储库中的依赖项。 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",

you might have used npm i and the editor might fail to generate the build correctly.您可能使用过 npm i 并且编辑器可能无法正确生成构建。 Try restarting your editor.尝试重新启动您的编辑器。 Restarting worked for me.重新启动对我有用。 I was using VSCode我正在使用 VSCode

#2 在我不小心在项目文件夹而不是 dist 文件夹中使用npm link后发生在我身上。

I have this error because i deleted everything from one of my components ts file inorder to copy paste the code my instructor我有这个错误,因为我从我的一个组件ts文件中删除了所有内容,以便将代码复制粘贴我的导师

then i deleted that component declaration from my app.module.ts file then it worked然后我从我的 app.module.ts 文件中删除了那个组件声明然后它工作了

I got the same error, but the solution that worked for me may be different from yours我遇到了同样的错误,但对我有用的解决方案可能与您的不同

I had different modules apart from app.module for example hom-page.mdule除了 app.module 之外,我还有不同的模块,例如 hom-page.mdule

I forgot to add Home-page.component to Home-page.module in the declarations section我忘了在声明部分将 Home-page.component 添加到 Home-page.module

Had the same issue.有同样的问题。 I had just switched to a git branch and I ran "npm install".我刚刚切换到一个 git 分支并运行了“npm install”。 The error was everywhere.错误无处不在。 All I did was restart my server.我所做的只是重新启动我的服务器。

If issues persist for anyone reading this, try deleting your node_modules folder and running npm install again.如果任何阅读本文的人仍然存在问题,请尝试删除您的 node_modules 文件夹并再次运行 npm install。

Regards问候

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AppModule 的 NgModule.imports 中的值 position 5 不是引用(构建错误 Angular2) - Value at position 5 in the NgModule.imports of AppModule is not a reference (build error Angular2) 导入 Angular 9 库时,“MyCommonLibraryModule 的 NgModule.imports 中位置 4 的值不是参考” - "Value at position 4 in the NgModule.imports of MyCommonLibraryModule is not a reference" when importing an Angular 9 library Angular 错误NG6002:出现在AppModule的NgModule.imports中,但无法解析为NgModule class - Angular error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class Angular更新8到9:NG6002:出现在AppModule的NgModule.imports中,但本身有错误 - Angular update 8 to 9: NG6002: Appears in the NgModule.imports of AppModule, but itself has errors Angular 12 迁移问题错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但本身有错误 - Angular 12 migration issue error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors 使用独立组件 Angular 14 并收到错误“出现在...的 NgModule.imports 中” - Using standalone components Angular 14 and getting error 'Appears in the NgModule.imports of...' 出现在 ProductsModule 的 NgModule.imports 中,但无法解析为 NgModule 类 - Appears in the NgModule.imports of ProductsModule, but could not be resolved to an NgModule class 错误:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule class - error : Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类 - Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 出现在ExtendedSearchModule的NgModule.imports,但本身有错误? - Appears in the NgModule.imports of ExtendedSearchModule, but itself has errors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM