龙哥网

龙哥网

nodejs ejs使用include引入公共文件报错SyntaxError: Unexpected identifier
2021-12-17

ejs 3.1.5版本,根据网上的视频教程,使用include引用公共部分的html文件时出现错误

引入代码

<%include footer.html%>

报错

SyntaxError: Unexpected identifier in E:\project\nodejs\views\index.html while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
    at new Function (<anonymous>)
    at Template.compile (E:\project\nodejs\node_modules\_ejs@3.1.5@ejs\lib\ejs.js:661:12)
    at Object.compile (E:\project\nodejs\node_modules\_ejs@3.1.5@ejs\lib\ejs.js:396:16)
    at handleCache (E:\project\nodejs\node_modules\_ejs@3.1.5@ejs\lib\ejs.js:233:18)
    at tryHandleCache (E:\project\nodejs\node_modules\_ejs@3.1.5@ejs\lib\ejs.js:272:16)
    at View.exports.renderFile [as engine] (E:\project\nodejs\node_modules\_ejs@3.1.5@ejs\lib\ejs.js:489:10)
    at View.render (E:\project\nodejs\node_modules\_express@4.17.1@express\lib\view.js:135:8)
    at tryRender (E:\project\nodejs\node_modules\_express@4.17.1@express\lib\application.js:640:10)
    at Function.render (E:\project\nodejs\node_modules\_express@4.17.1@express\lib\application.js:592:3)
    at ServerResponse.render (E:\project\nodejs\node_modules\_express@4.17.1@express\lib\response.js:1012:7)

网上搜索后,改成下面的写法后,问题解决

<%-include ("footer.html")%>

原因可能是ejs版本问题~

免责声明
本站部分资源来源于互联网 如有侵权 请联系站长删除
龙哥网是优质的互联网科技创业资源_行业项目分享_网络知识引流变现方法的平台为广大网友提供学习互联网相关知识_内容变现的方法。