gpt4 book ai didi

angular - 导入 Angular 9 库时出现 "Value at position 4 in the NgModule.imports of MyCommonLibraryModule is not a reference"

转载 作者:行者123 更新时间:2023-12-04 10:30:01 25 4
gpt4 key购买 nike

我有两个通过 Angular 库共享公共(public)代码的 Angular 项目。我跑了ng update在两个项目和我的 Angular 库中尝试从 Angular 8 升级到 9。迁移脚本改变了我的 tsconfig.app.json文件来自

  "include": [
"../src/**/*"
]


  "files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]

Angular's migration guide状态

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.



当我尝试运行我的应用程序( ng serve 来自使用该库的项目之一)时,出现错误
ERROR 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 ],
~~~~~~~~~~~~~~~~~~~~~

如果我更换图书馆的 tsconfig.app.json回到
  "include": [
"../src/**/*"
]

然后一切正常。所以我想我的问题是
  • ng update不打算与图书馆合作?
  • 这是一个错误吗?
  • 我的“修复”是否可以,还是我错过了一些 Angular 9 优化?有没有更好的办法?
  • 最佳答案

    根据文件 https://update.angular.io/#8.0:9.0我们应该从特定组件中深度导入

    import {MatAutocompleteModule} from '@angular/material/autocomplete';
    @NgModule({
    imports: [
    MatAutocompleteModule
    ]

    关于angular - 导入 Angular 9 库时出现 "Value at position 4 in the NgModule.imports of MyCommonLibraryModule is not a reference",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60458673/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com