【发布时间】:2017-09-05 01:17:04
【问题描述】:
我是 Angular2 的新手,并且对于将其整合到 ASP.NET Web 应用程序中非常陌生。 当我尝试在我的 Angular2 ASP.NET Web 应用程序中以调试模式构建时出现此错误。在发布模式下构建时,我遇到了同样的错误。
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
An unhandled exception has occurred while executing the request
Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Prerendering failed because of error: ReferenceError: window is not defined
at D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:89981:21
at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:90732:3)
at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:90734:30)
at __webpack_require__ (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:21:30)
at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:85385:1)
at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:85386:30)
at __webpack_require__ (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:21:30)
at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\main-server.js:20466:42)
at __webpack_require__ (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\main-server.js:20:30)
at Object.exports.REPLACEMENT_CHARACTER (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\main-server.js:398:79)
Current directory is: D:\Projects\BryterOpsAdmin\BryterOpsAdmin
我刚刚在 mvc 端对模型类进行了一些微不足道的更改,所以当我收到此错误时,我恢复了我的更改并再次尝试。 我仍然收到此错误。根据我的源代码管理,自上次正常工作以来绝对没有任何变化。 什么可能导致此错误?我完全不知道要寻找什么。
我在 StackOverflow 上搜索了任何相关内容,但除了这个问题之外,我没有找到任何适用于 asp.net 的内容:Prerendering failed because of error: ReferenceError: window is not defined 从来没有回答过。
我尝试删除隐藏的 obj 和 bin 文件夹无济于事。
提前谢谢你。
更新: 我尝试直接导航到我网站上的一个页面,它成功地做到了。看来Angular2不再自动路由了。我仍然通过 MVC('Home/Index')点击 Home Controller 和 Home Index.cshtml 视图,所以这似乎是一个 Angular2 问题。
这就是我的 angular2 路由的样子。
`
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },
{ path: 'bryterUsers', component: BryterUsersComponent },
{ path: 'adminUsers', component: AdminUsersComponent },
{ path: 'retailers', component: RetailersComponent },
{ path: 'providers', component: ProvidersComponent },
{ path: '**', redirectTo: 'home' }
])`
UPDATE2:我现在无法导航到任何其他页面。无论走到哪里,我都会收到“未定义窗口”错误。我的代码中没有任何更改。我完全被难住了。任何帮助将不胜感激。
【问题讨论】: