我正在使用我的应用程序,并且它在几个小时前就可以运行了。但是现在,当我启动它时,出现以下错误。
/views
中没有/lib
目录,但是我的src/
中有。它包含error.jade.
我已经尝试了一切。删除/lib
,然后重新安装所有内容...
错误:无法在视图目录中查找视图“错误” “ /用户/ vemundeldegard /所有/服务器/ lib /视图” 在Function.render(/Users/vemundeldegard/all/server/node_modules/express/lib/application.js:580:17) 在ServerResponse.render(/Users/vemundeldegard/all/server/node_modules/express/lib/response.js:1008:7) 在/Users/vemundeldegard/all/server/lib/app.js:47:7 在Layer.handle_error(/Users/vemundeldegard/all/server/node_modules/express/lib/router/layer.js:71:5) 在trim_prefix(/Users/vemundeldegard/all/server/node_modules/express/lib/router/index.js:315:13) 在/Users/vemundeldegard/all/server/node_modules/express/lib/router/index.js:284:7 在Function.process_params(/Users/vemundeldegard/all/server/node_modules/express/lib/router/index.js:335:12) 在下一个(/Users/vemundeldegard/all/server/node_modules/express/lib/router/index.js:275:10) 在Layer.handle_error(/Users/vemundeldegard/all/server/node_modules/express/lib/router/layer.js:67:12) 在trim_prefix(/Users/vemundeldegard/all/server/node_modules/express/lib/router/index.js:315:13)
App.js
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var { BUILD_DIR, PUBLIC_DIR } = require('./paths');
var reactRenderer = require('./react-renderer');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.get('/', reactRenderer);
app.use(express.static(BUILD_DIR));
app.use(express.static(PUBLIC_DIR));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
Paths.js:
"use strict";
var path = require('path');
var BUILD_DIR = path.join(__dirname, '..', '..', 'client', 'build');
var PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');
module.exports = {
BUILD_DIR: BUILD_DIR,
PUBLIC_DIR: PUBLIC_DIR
};
答案 0 :(得分:0)
(我想发表评论,但是我没有足够的代表)
__dirname
的使用引起了我的注意-您是否可能无意中从错误的目录(在这种情况下为lib
)运行应用程序?