ng-bootstrap : ReferenceError: Document is not defined

ng-bootstrap : ReferenceError: Document is not defined

我有一个 Angular 6 SSR 应用程序,我已经向它添加了 ng-bootstrap,但是在 SSR 构建和 运行 上,我收到以下错误消息:

ReferenceError: Document is not defined
    at NgbFocusTrapFactory.ctorParameters (J:\Java\workstation\front\.server\server.js:2221:48333)
    at ReflectionCapabilities._ownParameters (J:\Java\workstation\front\.server\server.js:76:1668)
    at ReflectionCapabilities.parameters (J:\Java\workstation\front\.server\server.js:76:2482)
    at JitReflector.parameters (J:\Java\workstation\front\.server\server.js:3226:919)
    at CompileMetadataResolver._getDependenciesMetadata (J:\Java\workstation\front\.server\server.js:2665:25829)
    at CompileMetadataResolver._getTypeMetadata (J:\Java\workstation\front\.server\server.js:2665:23935)
    at CompileMetadataResolver._getInjectableTypeMetadata (J:\Java\workstation\front\.server\server.js:2665:31300)
    at CompileMetadataResolver.getProviderMetadata (J:\Java\workstation\front\.server\server.js:2665:31593)
    at J:\Java\workstation\front\.server\server.js:2665:29171
    at Array.forEach (<anonymous>)

为什么我得到 Document is not defined? 我应该用 Webpack 做点什么吗?

webpack : ^4.0.0
angular": 6.0.0-rc.6, 
ng-bootstrap: ^2.0.0,

jsdom-global解决了这个问题。

jsdom-global will inject document, window and other DOM API into your Node.js environment. Useful for running, in Node.js, tests that are made for browsers.

1) 运行: npm install --save-dev --save-exact jsdom jsdom-global

2) 在vendor.ts

中添加:require('jsdom-global')()