问题描述
我是 Angular2 的新手,我正在尝试通过演示项目进行功能测试并使用预渲染在代码中使用 Webpack .
I am new in Angular2, I am trying to go through functionalities with a demo project and used prerendering with Webpack in the code.
我的代码在这里-
https://github.com/abrarjahin/Dot.NetCore_Angular2_App
我收到此错误-
An unhandled exception occurred while processing the request.
Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: window is not defined
at D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:6541
at D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:6473
at e.exports (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:6759)
at Object.<anonymous> (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:3513)
at t (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:217)
at Object.<anonymous> (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:3381)
at t (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:217)
at Object.e.exports (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:2992)
at t (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:217)
at Object.<anonymous> (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:1615)
at t (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:217)
at Object.<anonymous> (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:779)
at t (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:217)
at Zone.current.fork.name (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:310)
at Object.<anonymous> (D:\Dot.NetCore_Angular2_App\ProfileManagement\ClientApp\dist\main-server.js:1:315)
Current directory is: D:\Dot.NetCore_Angular2_App\ProfileManagement
我从未在代码中使用任何窗口.
I never used any window in my code.
有人知道为什么我会收到此错误吗?
Does anyone have any idea why I am getting this error?
我已经检查了这个问题- AngularJS ReferenceError:未定义$ window
I had checked this question - AngularJS ReferenceError: $window is not defined
但这没有帮助.
预先感谢您的帮助.
推荐答案
导入npm模块时,我遇到了同样的问题,我通过替换Index.cshtml页面上应用程序组件的prerender属性来解决此问题:
I had the same issue when import npm modules, I fixed this by replacing prerender attribute for app component at Index.cshtml page:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
到
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>
也许对您有帮助.
这篇关于由于以下原因,预渲染失败:ReferenceError:未定义窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!