4

我已经浏览了 SO 和其他各种网站大约 4 个小时,试图弄清楚如何解决这个问题,但我似乎找不到任何可以让我加载页面的解决方案,除了破坏预渲染的解决方案。

建议更改:

<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>

<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>

这将导致页面加载,但它会破坏预渲染并且(随着时间的推移)似乎会导致网站上出现奇怪的伪影(例如,我的辅助导航菜单加载时没有样式)

我得到的错误

Exception: Call to Node module failed with error: ReferenceError: document is not defined
at DefaultDomRenderer2.module.exports.DefaultDomRenderer2.selectRootElement (D:\_angular\ngageonline\ClientApp\dist\vendor.js:22930:72)
at BaseAnimationRenderer.selectRootElement (D:\_angular\ngageonline\ClientApp\dist\main-server.js:11230:106)
at createElement (D:\_angular\ngageonline\ClientApp\dist\vendor.js:14280:23)
at createViewNodes (D:\_angular\ngageonline\ClientApp\dist\vendor.js:17260:44)
at createRootView (D:\_angular\ngageonline\ClientApp\dist\vendor.js:17189:5)
at Object.createProdRootView [as createRootView] (D:\_angular\ngageonline\ClientApp\dist\vendor.js:17874:12)
at ComponentFactory_.module.exports.ComponentFactory_.create (D:\_angular\ngageonline\ClientApp\dist\vendor.js:14966:46)
at ComponentFactoryBoundToModule.module.exports.ComponentFactoryBoundToModule.create (D:\_angular\ngageonline\ClientApp\dist\vendor.js:8440:29)
at ApplicationRef_.module.exports.ApplicationRef_.bootstrap (D:\_angular\ngageonline\ClientApp\dist\vendor.js:9870:57)
at D:\_angular\ngageonline\ClientApp\dist\vendor.js:9653:81

我已经尝试尽可能多地更新,但即使使用最新版本的 Angular,问题也是一样的(从 4.1.2 升级到 4.3.5)。

我在 .NET Core 项目<TargetFramework>netcoreapp1.1.1</TargetFramework>中运行 Angular,关于它的教程并不多。由于我是使用 .NET Core 的 Angular 新手,因此有许多与常规 Angular 应用程序的设置略有不同的东西,让我很困惑,让我忙了一段时间,但这似乎完全超出了我的范围。

包.json

{
  "name": "ngageonline",
  "version": "0.0.0",
  "dependencies": {
    "@angular/animations": "^4.3.5",
    "@angular/common": "^4.3.5",
    "@angular/compiler": "^4.3.5",
    "@angular/compiler-cli": "^4.3.5",
    "@angular/core": "^4.3.5",
    "@angular/forms": "^4.3.5",
    "@angular/http": "^4.3.5",
    "@angular/platform-browser": "^4.3.5",
    "@angular/platform-browser-dynamic": "^4.3.5",
    "@angular/platform-server": "^4.3.5",
    "@angular/router": "^4.3.5",
    "@types/node": "7.0.18",
    "angular2-chartjs": "^0.2.0",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^2.0.5",
    "aspnet-webpack": "^1.0.29",
    "awesome-typescript-loader": "3.1.3",
    "bootstrap": "3.3.7",
    "chartjs": "^0.3.24",
    "css": "2.2.1",
    "css-loader": "0.28.1",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.0",
    "file-loader": "0.11.1",
    "font-awesome": "^4.7.0",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.4.3",
    "style-loader": "0.17.0",
    "to-string-loader": "1.1.5",
    "typescript": "^2.4.2",
    "url-loader": "0.5.8",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.0",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.10"
  },
  "devDependencies": {
    "@angular/cli": "^1.3.1",
    "@angular/compiler-cli": "^4.3.5"
  }
}

app.module.ts的相关部分:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';

export const sharedConfig: NgModule = {
    bootstrap: [AppRootComponent],
    declarations: [
        ...
    ],
    imports: [
        ...
        BrowserModule,
        BrowserAnimationsModule
    ],
    providers: [
        ...
    ]
};

我很想用 Angular Animations再次运行它,而不会失去prerender的能力。我希望你们能指出我正确的方向。如果您需要更多信息,请告诉我。

4

0 回答 0