Error: Could not find the include file “partials/head”

微笑、不失礼 提交于 2020-04-30 11:11:05

问题


enter image description hereI am trying to run an ejs file and gets error Error: Could not find the include file "partials/head".

i have checked most of the articles from stackoverflow and github however not able to resolve it ...

Error: Could not find the include file "partials/head" at getIncludePath (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:162:13) enter code here at includeSource (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:306:17) at C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:672:26 at Array.forEach () at Template.generateSource (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:648:15) at Template.compile (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:552:12) at Object.compile (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:388:16) at handleCache (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:212:18) at tryHandleCache (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:251:16) at View.exports.renderFile [as engine] (C:\Users\Junia\Desktop\node\node_modules\ejs\lib\ejs.js:480:10)

var express=require('express');

var app=express();

var router=express.Router();

var mysql=require('mysql');

var cookieParser=require('cookie-parser');

var session=require('express-session');

app.use(session({
    secret: 'secret',
    resave: true,
    saveUninitialized: true
    //cookie : { maxAge : 60000 }
}));

var path=require('path');

var bodyParser=require('body-parser');

app.use(express.static('/'));

//Serves all the request which includes /images in the url from Images folder

app.use('/images', express.static(__dirname + '/images'));

app.use('/bs4', express.static(__dirname + '/bs4'));

app.use(cookieParser());

const ejsLint = require('ejs-lint');

var con=mysql.createConnection(

{

host:'localhost',

user:'root',

password:'',

database:'shintoj'

});

var path = require('path');

app.use('/',router);

app.use('/',express.static(__dirname + '/'));

app.set('views', path.join(__dirname, 'views/pages'));

app.set('view engine', 'ejs');// use res.render to load up an ejs view file

// index page 

router.get('/', function(req, res) {

    //res.send('Welcome');

    res.render('index');

});

app.listen(8080);

console.log('8080 is the magic port');

console.log(app.get('views'));

index.ejs file

<head>

<%- include partials/head %>

</head>

<body class="container">

<header>

<% include partials/header.ejs %>

</header>

    <div class="jumbotron">

        <h2>Welcome to our services .</h2>

        <p>Hello</p>

    </div>

<footer>

<% include partials/footer.ejs %>

</footer>   

expected actual result is .. when i run node server.js , it should display the index.ejs file


回答1:


Remove include tag header and footer from ejs tag in your index.ejs file. Or jsut include header and footer file properly. Like this

<%- include views-directory/filename  %>



回答2:


This can happen, given the way you are calling the page you need, currently the correct way to get one page within another is

<%- include('partials/navigation.html')%>


来源:https://stackoverflow.com/questions/54731348/error-could-not-find-the-include-file-partials-head

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!