Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 查找视图失败";索引“;“在视图目录中”/root/client/dist/dist/browser“;_Angular - Fatal编程技术网

Angular 查找视图失败";索引“;“在视图目录中”/root/client/dist/dist/browser“;

Angular 查找视图失败";索引“;“在视图目录中”/root/client/dist/dist/browser“;,angular,Angular,运行Angular 7 Universal应用程序后,出现了一个错误 无法在视图目录“/root/client/dist/dist/browser”中查找视图“索引” 问题似乎出在客户端站点上 我已经安装了软件包并重新构建了应用程序。应用程序正在运行,但如果启动浏览器,则会出现错误 错误:无法在函数处的视图目录“/root/client/dist/dist/browser”中查找视图“index”。render(/root/client/ 位于ServerResponse.render(/roo

运行Angular 7 Universal应用程序后,出现了一个错误

无法在视图目录“/root/client/dist/dist/browser”中查找视图“索引”

问题似乎出在客户端站点上

我已经安装了软件包并重新构建了应用程序。应用程序正在运行,但如果启动浏览器,则会出现错误

错误:无法在函数处的视图目录“/root/client/dist/dist/browser”中查找视图“index”。render(/root/client/ 位于ServerResponse.render(/root/client)的dist/server.js:49345:17)/ dist/server.js:58250:7)位于/root/client/dist/server.js: 138:9位于层。句柄[作为句柄请求](/root/client/dist)/ server.js:51131:5)在下一个(/root/client/dist/server.js:50879: 13) at Route.dispatch(/root/client/dist/server.js:50854:3)at Layer.handle[作为handle_请求](/root/client/dist/server.js: 51131:5)at/root/client/dist/server.js:50354:22 at param(/root/client/dist/server.js:50427:14)位于 param(/root/client/dist/server.js:50438:14)

解决方案

// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';

import {
    enableProdMode
} from '@angular/core';

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();

declare var window;
const PORT = process.env.PORT || 4200;
const DIST_FOLDER = join(process.cwd(), 'dist');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {
    AppServerModuleNgFactory,
    LAZY_MODULE_MAP
} = require('./dist/server/main');

// Express Engine
import {
    ngExpressEngine
} from '@nguniversal/express-engine';
// Import module map for lazy loading
import {
    provideModuleMap
} from '@nguniversal/module-map-ngfactory-loader';



app.engine('html', ngExpressEngine({
    bootstrap: AppServerModuleNgFactory,
    providers: [
        provideModuleMap(LAZY_MODULE_MAP)
    ]
}));

app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

// TODO: implement data requests securely
app.get('/api/*', (req, res) => {
    res.status(404).send('data requests are not supported');
});

// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

// 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 server listening on http://localhost:${PORT}`);
});