我一直在浏览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,并没有那么多关于它的教程。由于我是Angular和.NET Core的新手,有很多东西与常规的Angular应用程序设置略有不同,让我感到困惑,让我忙碌了一段时间,但这似乎完全超出了我。
的package.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 的能力。我希望你们能指出我正确的方向。 如果您需要更多信息,请告诉我。