我正在使用Angular 10在我的项目中应用SSR。
我发现很多人推荐使用domino。
下面是我的server.ts文件
...
import { existsSync, readFileSync } from 'fs';
import { createWindow } from 'domino';
const scripts = readFileSync('dist/video-website-angular/browser/index.html').toString();
const window = createWindow(scripts);
global['window'] = window;
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common';
...当我运行npm run dev:ssr时,我得到error
发布于 2021-01-31 05:20:14
实际上,this.debug is not a function错误只是一个副作用。实际的错误是第一个:

为了修复它,您需要将window声明为any,如下所示:
const window: any = createWindow(scripts);
// or via a cast
const window = createWindow(scripts) as any;还有另一种我最不喜欢的方法,因为它实际上使TS代码的行为像JS一样,并切断了所有类型和代码提示的支持,但它是这样的:
(global as any).window = window;
(global as any).document = window.document;
(global as any).Event = window.Event;
(global as any).KeyboardEvent = window.KeyboardEvent;这两种方法都可以解决您的问题。
https://stackoverflow.com/questions/65966642
复制相似问题