javascript - 如何在 Node/Express 中调试 EJS 模板

标签 javascript node.js express

我正在将 PHP 模板转换为 Node.js/Express 中的 EJS。模板文件有些复杂,因此调试它们并不容易。 Node 没有给我任何有用的调试信息,所以这几乎不可能完成这项任务。这是错误消息示例。

SyntaxError: Unexpected string in "app/views/profile/index.ejs"
    at Object.Function (<anonymous>)
    at exports.compile (/Users/Gavin/Web/node_modules/ejs/lib/ejs.js:237:14)
    at Object.exports.render (/Users/Gavin/Web/node_modules/ejs/lib/ejs.js:284:10)
    at View.exports.renderFile [as engine] (/Users/Gavin/Web/node_modules/ejs/lib/ejs.js:318:20)
    at View.render (/Users/Gavin/Web/node_modules/express/lib/view.js:76:8)
    at Function.app.render (/Users/Gavin/Web/node_modules/express/lib/application.js:502:10)
    at ServerResponse.res.render (/Users/Gavin/Web/node_modules/express/lib/response.js:777:7)
    at Object.exports.profile_index [as handle] (/Users/Gavin/Web/app/controllers/routes/profile.js:72:6)
    at next_layer (/Users/Gavin/Web/node_modules/express/lib/router/route.js:103:13)
    at Object.exports.verify_user [as handle] (/Users/Gavin/Web/app/controllers/routes/account.js:305:10)

查找这种模糊错误消息的来源非常乏味。有没有更简单的方法来调试 EJS 文件?

最佳答案

我同意错误消息含糊不清! 有一些开源应用程序在其应用程序中进行了更好的错误处理。 我用 Mean.Js

他们的消息更容易理解,它实际上指向一行代码并给你一些提示来纠正它。 它易于使用。

希望对您有所帮助!

关于javascript - 如何在 Node/Express 中调试 EJS 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24332481/

相关文章:

javascript - 尝试返回一个对象并显示其属性

javascript - 根据高度和宽度调整 div 的大小

mongodb - 如何在 node.js 和 mongodb 中实现 geoip

node.js - Coffeescript resetCards 不是函数

javascript - Angularjs 阻止页面加载并在点击时显示值

javascript - 如何检查对象属性?

javascript - 如何控制 NPM 在哪里找到 server.js?

node.js - re、res 是从哪里来的express

node.js - 如何从postman addon Nodejs Express获取表单数据中的值

html - 使用express获取node.js中选定的选项值