组件中的继承导致构建错误 Angular

Inheritance In Components Makes Build Error In Angular

我有一个这样的父组件:

import { Component} from '@angular/core';

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}

和一个扩展父组件的子组件:

import { Component} from '@angular/core';
import { ChildService} from './services';

@Component({
    selector: 'app-main-child',
    templateUrl: './child.component.html',
})
export class ChildComponent extends ParentComponent{

    constructor(private _childService: ChildService) {
        super(_childService);
    }
}

并在 main.module.ts 中添加了这些组件:

import { NgModule } from '@angular/core';
import { ParentComponent,
        ChildComponent } from './components'

@NgModule({
    imports: [
    ...
    ],
    declarations: [
        ParentComponent,
        ChildComponent,
        ...
    ],
    providers: [
    ...
    ]
})
export class MainModule { }

我使用以下命令构建项目:

npm run build

并得到这个错误:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
npm ERR! code ELIFECYCLE
npm ERR! errno 3
npm ERR! proj.panel@0.0.0 build: ng build --aot --prod --stats-json
npm ERR! Exit status 3
npm ERR!
npm ERR! Failed at the proj.panel@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache_logs18-01-17T10_37_32_166Z-debug.log

如果我从 main.module.ts 中删除 ParentComponent,则会出现此错误:

Cannot determine the module for class ParentComponent in
C:/Users/user/source/repos/proj/web-panel/app/main/components.ts!
Add ParentComponent to the NgModule to fix it.

其他内容:

  1. 如果我 运行 使用 npm start 命令进行项目,它工作正常。仅在构建 我遇到了这些错误。
  2. 我 运行 没有 aot 的构建命令 (ng build --no-aot --prod) 但是 错误仍然存​​在。
  3. 除了子组件,我没有在任何地方使用 ParentComponent 延长。

对于工具问题:

此错误与 RAM 消耗有关

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  • 清除所有 temp%temp% 文件夹
  • 使用以下脚本将您的 RAM 使用量限制为 4GB

    node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng serve --
    

注意:请注意您node_modules

的路径

所以我搜索了很多,并询问了所有我认为可以提供帮助的人,但没有一个解决方案。

然后我创建了一个新项目并复制了主项目中的所有文件,神奇地错误消失了。

问题不是关于组件中的继承,仍然不知道是什么导致了错误