Angular 组件中的继承会导致角度错误

Angular 组件中的继承会导致角度错误,angular,inheritance,build,angular-components,Angular,Inheritance,Build,Angular Components,我有这样一个父组件: import { Component} from '@angular/core'; @Component({ selector: 'app-main-parent', template: '', }) export class ParentComponent { constructor(protected service) { service.doSomething(); } } import { NgModule } f

我有这样一个父组件:

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

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}
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_logs\2018-01-17T10_37_32_166Z-debug.log
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.
和扩展父级的子组件:

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 { Component} from '@angular/core';

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}
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_logs\2018-01-17T10_37_32_166Z-debug.log
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.
我使用以下命令生成项目:

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

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}
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_logs\2018-01-17T10_37_32_166Z-debug.log
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.
并出现此错误:

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

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}
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_logs\2018-01-17T10_37_32_166Z-debug.log
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.
如果从main.module.ts中删除ParentComponent,则会出现以下错误:

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

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}
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_logs\2018-01-17T10_37_32_166Z-debug.log
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.
其他材料:

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

@Component({
    selector: 'app-main-parent',
    template: '',
})
export class ParentComponent {
    constructor(protected service) {
        service.doSomething();
    }
}
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_logs\2018-01-17T10_37_32_166Z-debug.log
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.
  • 若我用npmstart命令运行这个项目,它运行得很好。仅限内置 我犯了这些错误
  • 我在没有aot的情况下运行了build命令(ng build--no aot--prod),但是 错误仍然存在
  • 我不在任何地方使用ParentComponent,但用于childs组件 延伸
  • 对于工具问题:

    • 角度版本:5.0.0
    • 节点版本:6.11.4
    • 平台:视窗10
    • npm版本:5.6.0

    此错误与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 --
      

    注意:请注意您的
    节点\u模块的路径

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

    然后我创建了一个新项目,从主项目复制了所有文件,奇迹般地错误消失了


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

    您在teamviewer中可用的区域?这似乎是一个奇怪的问题。这个问题缺少CLI版本,而它在这里最相关。我不知道继承有什么问题会导致这样的问题。然后得到这个错误——当然,您需要从代码库中完全删除这个类。其他选项如
    ng build--dev
    ng build--no aot
    是否有错误?没有证据表明这个问题与继承有关。您是否尝试重构子类以不扩展类?@Aravind否,但我有AnyDeskchrome远程桌面?@estus Angular CLI:1.5.5,您需要将该类从代码库中完全删除,抱歉,我没有理解您的意思?其他选项(如ng build--dev和ng build--no aot)是否有错误?是的,与以前相同,没有区别。没有证据表明这个问题与继承有关。你试过。。。不,重构的时间太长了,因为有很多组件,但我确信,唯一的变化是继承的组件,之后我出现了错误