使用自定义组件库中的组件时出现角度“非法状态:无法加载指令摘要”

当存在相冲突的软件包版本时,我的Angular项目无法编译(ng build --prod)。我们正在使用内部构建并发布到本地NPM存储库的一组组件。

当项目中使用冲突版本时,这些组件将安装在从属组件内的node_modules中。例如,

in application package.json
dependencies: {
   "A": "1.0.0","B": "1.0.0"
   ...
}
A's package.json (in library)
{
   version: "1.0.0",dependencies: {
      "X": "1.0.0"
   }
}
B's package.json (in library)
{
   version: "1.0.0",dependencies: {
      "X": "2.0.0"
   }
}
X's package.json (in library)
{
   version: "1.0.0",dependencies: {
      "Y": "1.0.0"
   }
}

{
   version: "2.0.0",dependencies: {
      "Y": "2.0.0"
   }
}

当我在应用程序中安装软件包(npm install)时,软件包的安装如下,

/
   node_modules/
      A@1.0.0
      X@1.0.0
      Y@1.0.0
      B@1.0.0
         node_modules
            X@2.0.0
            Y@2.0.0

据我所知,这是NPM方面的预期行为。

但是,当我尝试使用ng build --prod构建应用程序时,出现以下错误。

Illegal state: Could not load the summary for directive MenuComponent in E:/projects/ntc/node_modules/@tc/profile/node_modules/@tc/menu/menu.component.d.ts

(在这种情况下,“菜单”就像“ Y”一样,它是第二级依赖项)

该库项目遵循旧的Angular Material组件库结构,并使用 ngc 编译器(ngc -p ./src/lib/tsconfig-ngc.json)来构建所有组件。

tsconfig-ngc.json
{
  "$schema": "http://json.schemastore.org/tsconfig","angularCompilerOptions": {
    "debug": true,"fullTemplateTypeCheck": true,"genDir": "./../dist/@tc","skipTemplateCodegen": true,"strictMetadataEmit": true,"enableResourceInlining": true
  },"compilerOptions": {
    "baseUrl": ".","declaration": true,"experimentalDecorators": true,"inlinesources": true,"lib": [
      "es6","dom"
    ],"module": "es2015","moduleResolution": "node","outDir": "./../../dist/@tc","paths": {
      "@tc/*": [
        "./*"
      ]
    },"rootDir": ".","sourceMap": true,"stripInternal": true,"target": "es5","typeRoots": [
      "../node_modules/@types"
    ],"types": []
  },"include": [
    "**/*.ts"
  ],"exclude": [
    "**/*.spec.ts"
  ]
}

我有什么想念的吗?此问题的根本原因是什么?

ludyhhm 回答:使用自定义组件库中的组件时出现角度“非法状态:无法加载指令摘要”

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3104874.html

大家都在问