node.js - ReferenceError:未定义窗口 Angular Universal
问题描述
我正在使用 Angular 10 并尝试在我的项目中实现 SSR。
当我运行时,npm run serve:ssr
我收到以下错误
ReferenceError: window is not defined
当我用谷歌搜索时,他们建议添加domino
所以下面是我的 server.ts
....
const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString();
const window = domino.createWindow(scripts);
global['window'] = window;
global['document'] = window.document;
....
仍然出现相同的错误,请指导我如何解决此问题。
解决方案
很简单的解决方法
我已经导入了AppServerModule
afterglobal['window']
并且它有效
global['window'] = window;
global['document'] = window.document;
import { AppServerModule } from '../../projects/asfc-web/src/main.server';
推荐阅读
- ruby-on-rails - 新 Rails 应用程序的 /tmp/cache/ 中的文件(258 个目录,1404 个文件)
- git - “拆分和拼接”可以管理包含大量文件的 GIT 存储库吗?
- javascript - 如何在 jQuery Validate Engine 上执行 minCheckBox 验证?
- sql-server - 子表单查询标准正在延续到新记录
- php - 无法通过 PDO 连接,但命令行工作正常
- python - 合并连续匹配的行
- java - 如何在字符串中查找特定数字 Java
- android - 从片段的片段中打开片段?
- python - 没有循环事件的python aiohttp和asyncio
- c# - vscode omnisharp 在新文件中找不到类