Asp.Net Core + Angular:NodeInvocationException:由于“ClientApp / dist / main-server”中的启动功能,预渲染在30000ms后超时

时间:2017-11-30 03:49:24

标签: angular asp.net-core

我从使用角度项目模板创建的ASP.NET Core网站收到以下服务器错误。

NodeInvocationException: Prerendering timed out after 30000ms because the boot function in 'ClientApp/dist/main-server' returned a promise that did not resolve or reject. Make sure that your boot function always resolves or rejects its promise. You can change the timeout value using the 'asp-prerender-timeout' tag helper.

如果我删除了dealService.getDeals()中的deal.component.ts,则此错误消失了 如何在不删除对getDeals()的调用的情况下解决此问题?

file:deal.component.ts

import { Component } from '@angular/core';
import { DealService } from './deal.service'
import { Deal } from './deal'

@Component({
    selector: 'deal',
    templateUrl: './deal.component.html',
    styleUrls: ['./deal.component.css']
})
export class DealComponent {
    deals: Deal[] = [
        { title: 'Title #1', desc: 'Desc #1' },
        { title: 'Title #2', desc: 'Desc #2' }
    ];
    constructor(private dealService: DealService) {    
        dealService.getDeals();
    }

file:deal.service.ts

import { Injectable } from '@angular/core';
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { List } from 'immutable';
import { Deal } from './deal'
import 'rxjs/add/operator/toPromise';
@Injectable()
export class DealService {

    constructor(private http: Http, @Inject('BASE_URL') private baseUrl: string) {        
    }

    getDeals(): Promise<Deal[]> {
        return this.http.get(this.baseUrl + "api/Deal/All")
            .toPromise()
            .then(response => response.json().data as Deal[])
            .catch(this.handleError);        
    }

    private handleError(error: any): Promise<any> {
        console.error('An error occurred', error); // for demo purposes only
        return Promise.reject(error.message || error);
    }
}

1 个答案:

答案 0 :(得分:3)

我找到了解决方案。我错误输入了HTTP端点,它应该是&#34; api / Deals / All&#34;而不是&#34; api / Deal / All&#34;。

尽管如此,我真的不喜欢ASP.NET报告的错误消息,因为它不清楚出了什么问题。调试大型生产应用程序中的类似错误就像在干草堆中找到针一样。