ng serve导致错误:“无法使用名称空间作为类型”

时间:2019-09-12 13:50:26

标签: angular highcharts

尝试使用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版本

角度: 我正在使用角度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

2 个答案:

答案 0 :(得分:1)

要以高角度运行高图表,我们必须同时安装高图表和高角度图表。 "highcharts-angular": "^2.4.0", "highcharts": "^7.1.2"

答案 1 :(得分:1)

在您的代码中,我发现了奇怪的“ highcharts-angular”依赖性。我将其更改为"highcharts-angular": "^2.4.0",代码正常工作。

1)在您的应用中,删除node_modules文件夹(MAC上的rm -rf node_modules)
2)使用以下npm install配置运行package.json

{
  "name": "highcharts-angular-project",
  "private": true,
  "description": "Project to develop the Highcharts component for Angular. See the ./highcharts-angular folder for published project.",
  "version": "0.0.0",
  "license": "SEE LICENSE IN <LICENSE>",
  "author": "Black Label <start@blacklabel.pl> (http://blacklabel.pl)",
  "scripts": {
    "ng": "ng",
    "start": "node tasks/build.js && ng serve --open",
    "build": "node tasks/build.js",
    "test": "ng test highcharts-angular",
    "lint": "ng lint highcharts-angular",
    "release": "cd ./highcharts-angular && standard-version && cd ../ && node tasks/build.js && node tasks/release.js",
    "e2e": "ng e2e"
  },
  "dependencies": {
    "@angular-devkit/build-angular": "^0.10.0",
    "@angular/animations": "8.2.6",
    "@angular/common": "8.2.6",
    "@angular/compiler": "^8.2.6",
    "@angular/core": "8.2.6",
    "@angular/forms": "8.2.6",
    "@angular/http": "7.1.0",
    "@angular/platform-browser": "8.2.6",
    "@angular/platform-browser-dynamic": "8.2.6",
    "@angular/router": "8.2.6",
    "@highcharts/map-collection": "1.1.2",
    "core-js": "2.5.4",
    "highcharts": "^7.2.0",
    "highcharts-angular": "^2.4.0",
    "highcharts-custom-events": "2.2.2",
    "rxjs": "6.5.3",
    "tslib": "1.9.0",
    "zone.js": "0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-ng-packagr": "0.11.0",
    "@angular/cli": "^8.3.4",
    "@angular/compiler-cli": "^8.2.6",
    "@angular/language-service": "8.2.6",
    "@types/jasmine": "2.8.8",
    "@types/jasminewd2": "2.0.3",
    "@types/node": "8.9.4",
    "codelyzer": "4.5.0",
    "jasmine-core": "2.99.1",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "3.1.1",
    "karma-chrome-launcher": "2.2.0",
    "karma-coverage-istanbul-reporter": "2.0.1",
    "karma-jasmine": "1.1.2",
    "karma-jasmine-html-reporter": "0.2.2",
    "ng-packagr": "4.4.0",
    "protractor": "5.4.0",
    "standard-version": "4.4.0",
    "ts-node": "7.0.0",
    "tsickle": "0.25.5",
    "tslint": "5.11.0",
    "typescript": "3.5.3"
  }
}