问题
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?
回答1:
The problem was in package.json
Package @angular/common was in devDependencies. According to documentation of Electron builder (https://www.electron.build/configuration/contents) dev dependencies never copied to resulting package.
Moving dependencies that start with "@angular" to dependencies from devDependencies section in package.json solved the issues.
来源:https://stackoverflow.com/questions/62189392/extending-httperrorresponse-leads-to-error-cannot-find-module-angular-common-h