简体   繁体   中英

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

I have a model (defined in separate file) which extends HttpErrorResponse with custom property. Custom property is an interface with few properties:

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

This code works fine in debug mode, but when compiling to prod, I see error at runtime:

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

If I remove extension and just populate the same properties as HttpErrorResponse has, code works fine in prod, but I need to keep extension syntax.

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

This model is referenced from multiple components and interceptors and all of them are provided with dependency on @angular/common/http, so my questions are - what else I missed here and why it works in debug but doesn't work in prod mode?

I have a model (defined in separate file) which extends HttpErrorResponse with custom property. Custom property is an interface with few properties:

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

This code works fine in debug mode, but when compiling to prod, I see error at runtime:

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

If I remove extension and just populate the same properties as HttpErrorResponse has, code works fine in prod, but I need to keep extension syntax.

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

This model is referenced from multiple components and interceptors and all of them are provided with dependency on @angular/common/http, so my questions are - what else I missed here and why it works in debug but doesn't work in prod mode?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM