15

我将 Angular 应用程序从 v8 升级到 v9。该项目使用 Angular 8 和 moment.js 导入自定义 UI 库。

当我构建它时:

  1. 它会生成一个警告:
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.

@myLib/catalogue.js库文件(在 node_modules 文件夹内)中,moment.js DE 语言环境导入如下:

import 'moment/locale/de';


  1. 也会触发编译错误:
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                 ],
    ~~~~~~~~~~~~~~~~~

警告的文本​​似乎准确地解释了编译错误,其中位置(在本例中为 2)超出了导入数组的范围。

我看过关于深度链接的不同文章/ github 问题,但没有有效的解决方案。

4

6 回答 6

13

您可能使用过 npm i 并且编辑器可能无法正确生成构建。尝试重新启动编辑器。重新启动对我有用。我正在使用 VSCode

于 2021-07-09T14:32:48.980 回答
9

您需要更改您的自定义模块构建,因此您需要对以下内容进行模拟更改,在我的情况下,我需要更改:

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

至:

export class ThemeModule {
  static forRoot(): ModuleWithProviders<ThemeModule> {
    return {
      ngModule: ThemeModule,
      providers: [
        ...NbThemeModule.forRoot(
          {
            name: 'default',
          },
          [DEFAULT_THEME, COSMIC_THEME, CORPORATE_THEME, DARK_THEME],
        ).providers,
      ],
    };
  }
}
于 2020-04-16T08:32:45.583 回答
7

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 on my project side.

于 2020-04-16T09:04:12.680 回答
1

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

于 2020-07-07T13:58:20.663 回答
1

就我而言,我认为导入的一些 Angular 库之间存在一些不兼容性。我想我以前手动碰到@angular/material9.2.3而没有碰到其他角度库。

当我使用创建一个新存储库时:ng new test-ng9然后添加 angular material ng add @angular/material,没有编译问题。

因此,我采用了 angular cli 包含在临时存储库中的依赖项,并替换了我现有存储库中的依赖项。然后它工作得很好。

之前

    "@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",

之后

    "@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",
于 2020-05-19T12:09:19.500 回答
0

我有这个错误,因为我从我的一个组件文件中删除了所有内容,ts以便复制粘贴我的导师的代码

然后我从我的 app.module.ts 文件中删除了该组件声明然后它工作了

于 2021-06-28T05:03:06.407 回答