我的 ASP.NET Core Angular 2 网络应用出现间歇性异常:
Exception: Call to Node module failed with error: Error: This method is not implemented in Parse5DomAdapter: Parse5DomAdapter#getCookie
at _notImplemented (D:\Projects\MyProject\MyProject\node_modules\angular2-platform-node\parse5-adapter.js:22:12)
at Parse5DomAdapter.getCookie (D:\Projects\MyProject\MyProject\node_modules\angular2-platform-node\parse5-adapter.js:641:15)
at CookieXSRFStrategy.configureRequest (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:1597:92)
at XHRBackend.createConnection (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:1637:32)
at httpRequest (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:1975:24)
at Http.get (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:2086:20)
at ApiService.getChatMessages (D:\Projects\MyProject\MyProject\ClientApp\dist\main-server.js:557:20)
at ChatPageComponent.ngOnInit (D:\Projects\MyProject\MyProject\ClientApp\dist\main-server.js:513:23)
at AppView._View_ChatPageComponent_Host0.detectChangesInternal (ChatPageComponent_Host.ngfactory.js:30:86)
at AppView.detectChanges (D:\Projects\MyProject\MyProject\node_modules\@angular\core\bundles\core.umd.js:9566:18)
MoveNext
我认为这与 MVC View 有关,如错误所示:
MoveNext in Index.cshtml
1.@{
2. ViewData["Title"] = "Home Page";
3.}
4.
5.<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
6.
7.<script src="~/dist/vendor.js" asp-append-version="true"></script>
8.@section scripts {
这是我的 index.cshtml 中的代码。
这似乎发生在项目启动后的早期。这一切要么工作正常,要么在执行任何导航时加载主页后抛出错误。
我可以强制它产生错误。我有 4 个导航目的地:
http://localhost:49954/home
http://localhost:49954/counter
http://localhost:49954/fetch-data
http://localhost:49954/chat-page
这些都是通过 Visual Studio Angular 2 模板设置的。如果我刷新主页,一切都很好,如果它有机会加载一段时间,我可以导航到其他页面。但是,如果我输入任何其他页面的 url,它每次都会产生此错误。
编辑:此外,有趣的是,它会产生与 http://localhost:49954/counter
略有不同的错误。在我的计数器页面中,我使用了 Angular Material Design 组件:
<div class="mine">
<h2>
Counter Test
</h2>
<p>This is a simple example of an Angular 2 component.</p>
<p>Current count:<strong>{{ currentCount }}</strong></p>
<button md-raised-button (click)="incrementCounter()">Increment</button>
</div>
而不是上面的错误,它是一个类似的 Call to Node module failed 错误,但是在 Material 设计中:
Exception: Call to Node module failed with error: Error: Uncaught (in promise): ReferenceError: document is not defined
ReferenceError: document is not defined
at new RippleRenderer (D:\Projects\MyProject\MyProject\node_modules\@angular\material\material.umd.js:193:31)
最佳答案
这对我有用。变化:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
到
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>
在 index.html 中
关于asp.net - "Call to Node module failed with error"s 与 Angular2 & ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40257514/