如何用express和EJS正确“包含”一个使用node.js的EJS文件

我开始学习node.js,并且已经安装了express,并且正在使用Express来使用EJS。

我有以下代码(主要由快速生成器生成):

app.js

var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var routes = require('./routes/index'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); 

index.ejs

 <!DOCTYPE html> <html> <head><% include partials/head.ejs %></head> <body> <% include partials/header.ejs %> <h1><%= title %></h1> <p>Welcome to <%= title %></p> <% include partials/footer.ejs %> <% inlcude partials/javascripts.ejs %> </body> </html> 

javascripts.ejs

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script> 

我的问题是,我得到这个错误:

 Unexpected identifier in /var/www/HomeWatch.com/views/index.ejs while compiling ejs SyntaxError: Unexpected identifier in /var/www/HomeWatch.com/views/index.ejs while compiling ejs at Object.Function (<anonymous>) at Object.Template.compile (/var/www/HomeWatch.com/node_modules/ejs/lib/ejs.js:464:12) at Object.compile (/var/www/HomeWatch.com/node_modules/ejs/lib/ejs.js:288:16) at handleCache (/var/www/HomeWatch.com/node_modules/ejs/lib/ejs.js:147:16) at View.exports.renderFile [as engine] (/var/www/HomeWatch.com/node_modules/ejs/lib/ejs.js:350:14) at View.render (/var/www/HomeWatch.com/node_modules/express/lib/view.js:126:8) at tryRender (/var/www/HomeWatch.com/node_modules/express/lib/application.js:639:10) at EventEmitter.render (/var/www/HomeWatch.com/node_modules/express/lib/application.js:591:3) at ServerResponse.render (/var/www/HomeWatch.com/node_modules/express/lib/response.js:961:7) at module.exports (/var/www/HomeWatch.com/routes/index.js:6:7) 

它只有当包含javascripts.ejs,如果我删除它,页面加载罚款。

这是我的文件夹结构(我忽略了我不认为你需要的,但整个快递结构在那里)

 -bin --www routes -index.js views -partials --footer.ejs --head.ejs --header.ejs --javascripts.ejs -error.ejs -index.ejs app.js package.json 

似乎重命名为javascript.ejs javascript.ejs已经解决了这个问题…我甚至没有勇气问为什么…