首页 > 解决方案 > 带有 Fusionchart 的 Angular 6 - 找不到模块:错误:无法解析 fusionmaps/maps/fusioncharts.world

问题描述

我将使用 FusionChart (FC) 创建第一个交互式地图。从文档https://www.fusioncharts.com/dev/getting-started/angular/angular/your-first-map-using-angular我完成了所有步骤。但是,在ng serve我注意到错误期间:

找不到模块:错误:无法解析“/var/www/html/my-app/src/app”中的“fusionmaps/maps/fusioncharts.world”

./src/app/app.module.ts 未找到模块:错误:无法解析“/var/www/html/my-app/src/app”中的“fusionmaps/maps/fusioncharts.world”

从控制台,我看到了其他错误,例如:

GET http://localhost:5200/fusioncharts.world.js net::ERR_ABORTED

拒绝执行来自 ' http://localhost:5200/fusioncharts.world.js ' 的脚本,因为它的 MIME 类型 ('text/html') 不可执行,并且启用了严格的 MIME 类型检查。

我正在使用的 FusionChart 版本: 在此处输入图像描述

在我的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 { FusionChartsModule } from 'angular-fusioncharts';
import * as FusionCharts from 'fusioncharts';
import * as FusionMaps from 'fusioncharts/fusioncharts.maps';
import * as World from 'fusionmaps/maps/fusioncharts.world';

import * as FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
// Pass the fusioncharts library and chart modules
FusionChartsModule.fcRoot(FusionCharts, FusionMaps, World, FusionTheme);

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

app.component.ts

import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'my-app';
  public payPalConfig?: PayPalConfig;
  dataSource: Object;

  constructor() {
        this.dataSource = {
            "chart": {
                "caption": "Average Annual Population Growth",
                "subcaption": " 1955-2015",
                "numbersuffix": "%",
                "includevalueinlabels": "1",
                "labelsepchar": ": ",
                "entityFillHoverColor": "#FFF9C4",
                "theme": "fusion"
            },
            // Aesthetics; ranges synced with the slider
            "colorrange": {
                "minvalue": "0",
                "code": "#FFE0B2",
                "gradient": "1",
                "color": [{
                    "minvalue": "0.5",
                    "maxvalue": "1.0",
                    "color": "#FFD74D"
                }, {
                    "minvalue": "1.0",
                    "maxvalue": "2.0",
                    "color": "#FB8C00"
                }, {
                    "minvalue": "2.0",
                    "maxvalue": "3.0",
                    "color": "#E65100"
                }]
            },
            // Source data as JSON --> id represents countries of world.
            "data": [{
                "id": "NA",
                "value": ".82",
                "showLabel": "1"
            }, {
                "id": "SA",
                "value": "2.04",
                "showLabel": "1"
            }, {
                "id": "AS",
                "value": "1.78",
                "showLabel": "1"
            }, {
                "id": "EU",
                "value": ".40",
                "showLabel": "1"
            }, {
                "id": "AF",
                "value": "2.58",
                "showLabel": "1"
            }, {
                "id": "AU",
                "value": "1.30",
                "showLabel": "1"
            }]
        }
    }
}

.html文件中:

  <fusioncharts
    width="800"
    height="550"
    type="world"
    [dataSource]="dataSource">
</fusioncharts>

这是 package.json 的内容:

{
  "name": "my-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.0",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "angular-fusioncharts": "^3.0.0",
    "angular4-paystack": "^2.3.2",
    "core-js": "^2.6.2",
    "fusioncharts": "^3.13.3-sr.1",
    "ng2-password-strength-bar": "^1.2.3",
    "ngx-paypal": "^4.0.1",
    "rxjs": "~6.2.0",
    "zone.js": "^0.8.27"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.8.9",
    "@angular/cli": "^6.2.9",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "^2.8.14",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "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",
    "protractor": "^5.4.2",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  }
}

标签: angularfusioncharts

解决方案


Ashok 尽其所能帮助了我,他在我的电子邮件中为我提供了解决方案(正如我们在聊天中讨论的那样)。我已经实施了他通过电子邮件给我的内容,并且效果很好。现在,我将我的代码与他提供给我的代码进行了比较。我看到了一点点变化。见下文:

不工作

import * as World from 'fusionmaps/maps/fusioncharts.world';

在职的:

import * as World from 'fusioncharts/maps/fusioncharts.world';

我认为,fusioncharts 站点中的文档是错误的。


推荐阅读