从7.2更新到角度cli 7.3后出现延迟加载错误

时间:2019-02-28 11:09:26

标签: angular angular-cli

我有angular-cli@7.2,所以我更新了ng update -all 更新后,我无法运行ng serve,但出现错误:

ERROR in ./src/app/utils/lazy-loading.ts 57:49
Module parse failed: Unexpected token (57:49)
You may need an appropriate loader to handle this file type.
|             return __generator(this, function (_a) {
|                 switch (_a.label) {
>                     case 0: return [4 /*yield*/, import('@amcharts/amcharts4/core')];
|                     case 1:
|                         am4core = _a.sent();

关于我的带有该代码的延迟加载库:

export class LazyLoading {
  /**
   * Usage
   *
   LazyLoading.loadAmcharts()
   .then((
   {
            am4core,
            am4charts,
            am4themesAnimated,
          }
   ) => {});
   *
   */
  static async loadAmcharts(): Promise<any> {
    const am4core = await import('@amcharts/amcharts4/core');
    const am4charts = await import('@amcharts/amcharts4/charts');
    const am4themesAnimated = await import('@amcharts/amcharts4/themes/animated').then(resp => {
      return resp.default;
    });
    return {
      am4core: am4core,
      am4charts: am4charts,
      am4themesAnimated: am4themesAnimated,
    };
  }

  static async loadAmchartsMaps(): Promise<any> {
    const am4core = await import('@amcharts/amcharts4/core');
    const am4maps = await import('@amcharts/amcharts4/maps');
    const world = await import('@amcharts/amcharts4-geodata/worldLow').then(resp => {
      return resp.default;
    });
    const poland = await import('@amcharts/amcharts4-geodata/polandHigh').then(resp => {
      return resp.default;
    });
    const europe = await import('@amcharts/amcharts4-geodata/region/world/europeLow').then(resp => {
      return resp.default;
    });

    return {
      am4core: am4core,
      am4maps: am4maps,
      world: world,
      europe: europe,
      poland: poland,
    };
  }

  static async loadZXCVBN(): Promise<any> {
    const zxcvbn = await import ('zxcvbn').then(resp => {
      return resp.default;
    });
    return zxcvbn;
  }

  static async loadRrule(): Promise<any> {
    const Rrule = await import ('rrule/dist/esm/src/rrule')
      .then(resp => {
        return resp.default;
      });
    return Rrule;
  }
}

我不知道发生了什么变化。

这是我的tsconfig文件:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    //    "module": "es2015",
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "@app/*": [
        "src/app/*"
      ],
      "@mocks/*": [
        "src/mocks/*"
      ],
      "@decorators/*": [
        "src/app/utils/decorators/*"
      ]
    }
  }
}

0 个答案:

没有答案