EJS:ReferenceError:未定义漫游器

时间:2019-11-21 17:23:43

标签: node.js ejs discord.js

我想在Discord.js和EJS中创建一个机器人仪表板。

我有一个错误。

 >> 1| <%- include('blocks/header', {bot, user, path})%>

bot is not defined
    at eval (/app/dashboard/index.ejs:10:43)
    at index (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/ejs/2.7.4/node_modules/ejs/lib/ejs.js:682:17)
    at tryHandleCache (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/ejs/2.7.4/node_modules/ejs/lib/ejs.js:254:36)
    at View.exports.renderFile [as engine] (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/ejs/2.7.4/node_modules/ejs/lib/ejs.js:485:10)
    at View.render (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/express/4.17.1/node_modules/express/lib/view.js:135:8)
    at tryRender (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/express/4.17.1/node_modules/express/lib/application.js:640:10)
    at Function.render (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/express/4.17.1/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/express/4.17.1/node_modules/express/lib/response.js:1012:7)
    at app.get (/app/util/dashboard.js:45:7)
    at Layer.handle [as handle_request] (/rbd/pnpm-volume/694e46f9-27bb-4ad9-87e8-c675e51f8f94/node_modules/.registry.npmjs.org/express/4.17.1/node_modules/express/lib/router/layer.js:95:5)

但是我已经定义好了。

 const renderTemplate = (res, req, template, data = {}) => {
    const baseData = {
      bot: client,
      path: req.path,
      user: req.isAuthenticated() ? req.user : null
    };
    res.render(templateDir + path.sep + template, {baseData, data});
  };

我的index.ejs文件中包含一个include标记。

<%- include('blocks/header', {bot, user, path})%>

需要任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

解决此问题的方法是以不同的方式呈现它;

const renderTemplate = (res, req, template, data = {}) => {

 res.render(templateDir + path.sep + template), {
  bot: client,
  path: req.path,
  user: req.isAuthenticated() ? req.user : null
  data: data
 })
};