扩展 HttpErrorResponse 导致错误 Cannot find module '@angular/common/http'

Extending HttpErrorResponse leads to error Cannot find module '@angular/common/http'

我有一个模型(在单独的文件中定义),它使用自定义 属性 扩展了 HttpErrorResponse。自定义 属性 是一个具有少量属性的接口:

import { HttpErrorResponse } from '@angular/common/http';

export interface ApiErrorBody {
  id: number;
  code: string;
  message?: string;
  trace?: string;
}

export class ApiErrorResponse extends HttpErrorResponse {
  public error: ApiErrorBody;
}

此代码在调试模式下运行良好,但在编译为产品时,我在运行时看到错误:

Error: Cannot find module '@angular/common/http'

如果我删除扩展并只填充与 HttpErrorResponse 相同的属性,代码在产品中工作正常,但我需要保留扩展语法。

export interface ApiErrorBody {
  id: number;
  code: string;
  message?: string;
  trace?: string;
}

// no extension
export class ApiErrorResponse {
  public error: ApiErrorBody;
  public status: number;
  public message: string;
  piblic url: string;
}

这个模型是从多个组件和拦截器引用的,它们都依赖于@angular/common/http,所以我的问题是——我在这里还遗漏了什么以及为什么它在调试中工作但不工作在产品模式下工作?

问题出在package.json
包 @angular/common 在 devDependencies 中。根据 Electron 构建器 (https://www.electron.build/configuration/contents) 的文档,开发依赖项从未复制到生成的包中。

将以“@angular”开头的依赖项移动到 package.json 中 devDependencies 部分的依赖项解决了问题。