Я настроил рендеринг на стороне сервера с Angular 8, Angular Universe, ngx-bootstrap, и я получаю ошибку
ОШИБКА ReferenceError: документ не определен
в ModalContainerComponent.ngOnInit (/Users/user/project/dist/server.js:243925:9)
at checkAndUpdateDirectiveInline (/Users/user/project/dist/server.js:23530:19)
на checkAndUpdateNodeInline (/Users/user/project/dist/server.js:31788:20)
в checkAndUpdateNode (/Users/user/project/dist/server.js:31750:16)
в prodCheckAndUpdateNode (/Users/user/project/dist/server.js:32291:5)
в Object.updateDirectives (/Users/user/project/dist/server.js:137344:457)
в Object.updateDirectives (/Users/user/project//server.js:32079:72)
в Object.checkAndUpdateView (/Users/user/project//server.js:31732:14)
в ViewRef_.detectChanges (/Users/user/project//server.js:23119:22)
в ComponentLoader.show (/Users/user/project//server.js:241722:50)
Я пытался использовать домино в моем файле сервера, но это не помогло
"dependencies": {
"@angular/animations": "^8.0.0",
"@angular/cdk": "^8.0.0",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/forms": "^8.0.0",
"@angular/material": "^8.0.0",
"@angular/platform-browser": "^8.0.0",
"@angular/platform-browser-dynamic": "^8.0.0",
"@angular/platform-server": "^8.0.0",
"@angular/router": "^8.0.0",
"@nguniversal/express-engine": "^7.0.2",
"@nguniversal/module-map-ngfactory-loader": "v7.0.2",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"@types/lodash": "4.14.108",
"angular-font-awesome": "3.1.2",
"bootstrap": "4.1.3",
"core-js": "^2.4.1",
"express": "^4.15.2",
"font-awesome": "4.7.0",
"lodash": "4.17.4",
"moment": "2.22.2",
"ng-recaptcha": "4.2.1",
"ngx-bootstrap": "5.0.0",
"rxjs": "^6.5.2",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.800.0",
"@angular/cli": "8.0.2",
"@angular/compiler-cli": "^8.0.0",
"@angular/language-service": "^8.0.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.60",
"codelyzer": "^5.0.1",
"gulp": "^3.9.1",
"gulp-sass": "^4.0.1",
"gulp-watch": "^5.0.0",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-loader": "^5.2.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"tslint-sonarts": "^1.9.0",
"typescript": "~3.4.5",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.1.0"
}
server.ts
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import {enableProdMode} from '@angular/core';
// Express Engine
import {ngExpressEngine} from '@nguniversal/express-engine';
// Import module map for lazy loading
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
import * as express from 'express';
import {join} from 'path';
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
// Express server
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist/browser');
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', DIST_FOLDER);
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Server static files from /browser
app.get('*.*', express.static(DIST_FOLDER, {
maxAge: '1y'
}));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render('index', { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});