首页 > 解决方案 > ng serve 导致错误:“不能将命名空间用作类型”

问题描述

尝试使用 ng serve 编译应用程序时,出现以下错误:

ERROR in ../node_modules/highcharts-angular/lib/highcharts-chart.component.d.ts(3,58): error TS2709: Cannot use namespace 'OnDestroy' as a type.
../node_modules/highcharts-angular/lib/highcharts-chart.component.d.ts(13,19): error TS2709: Cannot use namespace 'EventEmitter' as a type.
../node_modules/highcharts-angular/lib/highcharts-chart.component.d.ts(14,20): error TS2709: Cannot use namespace 'EventEmitter' as a type.
../node_modules/highcharts-angular/lib/highcharts-chart.component.d.ts(17,21): error TS2709: Cannot use namespace 'ElementRef' as a type.
../node_modules/highcharts-angular/lib/highcharts-chart.component.d.ts(17,40): error TS2709: Cannot use namespace 'NgZone' as a type.

这里可能是什么问题?我没有找到解决办法。

版本:

最新的 Highcharts 版本

Angular:我使用的是 Angular 7.1.3。本地和全球 8.1.0

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';


import { AppComponent } from './app.component';
import { HighchartsChartModule } from 'highcharts-angular';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HighchartsChartModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我遵循了本指南: https ://github.com/highcharts/highcharts-angular

标签: angularhighcharts

解决方案


要以 Angular 运行 highcharts,我们必须同时安装 highcharts 和 highcharts-angular。 "highcharts-angular": "^2.4.0", "highcharts": "^7.1.2"


推荐阅读