2

从我目前所阅读的内容来看,添加 SSR 时可能会出现许多错误。在我的情况下,该属性Core/Utilities.js不能被读取为undefined

/home/user/Dokumente/microservices/frontend/dist/frontend/server/main.js:61297
                __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)):undefined})(function(a){function e(a,g,q,f){a.hasOwnProperty(g)||(a[g]=f.apply(null,q))}a=a?a._modules:{};e(a,"Mixins/IndicatorRequired.js",[a["Core/Utilities.js"]],function(a){var g=a.error;return{isParentLoaded:function(a,
                                                                                                                                                                                                                                                               ^

TypeError: Cannot read property 'Core/Utilities.js' of undefined

我已通过以下命令将 Universal 添加到我现有的 Angular 应用程序中

ng add @nguniversal/express-engine

并尝试运行它

npm run dev:ssr

我找不到任何有关缺少的Core/utilities.js模块的信息。我尝试安装 Node-Core-Utils npm install -g node-core-utils,但没有帮助。因为我不做太多与 javascript 相关的事情,所以我对 NPM 非常不熟悉。

4

1 回答 1

0

该问题与 highcharts-angular 包装器https://github.com/highcharts/highcharts-angular/issues/216有关。

我将尝试在即将发布的版本中从包装器级别修复该问题

解决方法

防止 Highcharts 在服务器端运行时呈现

export class AppComponent implements OnInit {
  isHighcharts = typeof Highcharts === 'object'; // new
  title = 'UnivHighCharts';
  Highcharts: typeof Highcharts = Highcharts;
  chartConstructor: string = 'chart';
  chartOptions: Highcharts.Options = {};

  ngOnInit() {
    this.chartOptions = {
      series: [{
        data: [1, 2, 3],
        type: 'line'
      }]
    };
  }
}
<highcharts-chart
  *ngIf="isHighcharts"
  [Highcharts]="Highcharts"
  [constructorType]="chartConstructor"
  [options]="chartOptions"
  style="width: 100%; height: 400px; display: block;"
></highcharts-chart>

(对我不起作用,但也阻止了模块在服务器端加载)

if (typeof Highcharts === 'object') {
    HC_More(Highcharts)
}
于 2020-11-03T07:51:14.870 回答