找不到包含文件 [英] Could not find include include file

查看:150
本文介绍了找不到包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个简单的服务器

I'm running a simple server

var express = require('express')
var app = express()

app.set('view engine', 'ejs'); 
app.use(express.static('public')) 

// home page request handler
app.get('/', function (req, res) {

    res.render('home')
})

// initializes request listener
app.listen(process.env.PORT, process.env.IP, function(){
    console.log("Server is listening");
})

当我对主页发出GET请求时,运行时抛出以下错误

When I make a GET request for the home page, run-time throws the following error

Error: Could not find include include file.
    at getIncludePath (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:152:13)
    at includeSource (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:276:17)
    at /home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:629:26
    at Array.forEach (native)
    at Object.generateSource (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:605:15)
    at Object.compile (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:509:12)
    at Object.compile (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:358:16)
    at handleCache (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:201:18)
    at tryHandleCache (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:223:14)
    at View.exports.renderFile [as engine] (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:437:10)

我不明白这个错误。有任何想法吗?我在Cloud9工作。

I don't understand this error. Any ideas? I'm working in Cloud9.

我的目录结构是

v1.1
  +---views
  |     +---- home.ejs
  |     +---- partials
  |               +------ header.ejs
  |               +------ footer.ejs
  |
  +----app.js

home.ejs

<% include header %>
<h1>welcome</h1>
<% include footer %>

header.ejs

<DOCTYPE! html>
    <html>
        <head>
            <title>
                <link rel="stylesheet" hreff="app.css">
            </title>
        </head>
    <body>

footer.ejs

    </body
</html>


推荐答案

包含路径是相对的,你需要更新你的包含partials子文件夹的路径,例如

Include paths are relative, you will need to update your paths to include the "partials" subfolder e.g.

<% include partials/header %>
<h1>welcome</h1>
<% include partials/footer %>

参见 docs

这篇关于找不到包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆