1

I'm using express-handlebars package (version: 4.0.4) and rendering my code like this:

app.get("/", (req, res) => {
    res.render('index', { title: 'Snowy' }, {
      allowProtoMethodsByDefault: true,
      allowProtoPropertiesByDefault: true
    });
})

But I am still getting same error. Any solution on Stackoverflow didn't work for me.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Kaan
  • 11
  • 6
  • Have a look at this thread, it is similar to your problem: https://stackoverflow.com/questions/59690923/handlebars-access-has-been-denied-to-resolve-the-property-from-because-it-is – eugen Jun 04 '20 at 12:26

1 Answers1

1

You will have to install older version of handlebar in your case. Paste this to your terminal and it should install the correct version of handlebars


npm uninstall express-handlebars && npm install express-handlebars@3.0.2


This version issue is probably related to your npm or node.js version on your machine.

  • The command below worked a little bit: `let { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access'); app.engine("handlebars", handlebars({ handlebars: allowInsecurePrototypeAccess(Handlebars) }));` I can access prototypes with this code (Example: `bot.users.cache.size`) bot cannot use commands like: `bot.users.cache.get("300573341591535617")` I get this error: `Expecting 'ID', got 'INVALID'` – Kaan May 01 '20 at 17:10
  • My code: `
    {{bot.users.cache.get("300573341591535617")}}
    `
    – Kaan May 01 '20 at 17:18
  • Hey, why did you removed you answers? – Kaan May 01 '20 at 17:22
  • It was a wrong approach that is why i have removed my previous answer.You know when i check the error message, i actually noticed one thing 'size'. May be you will need to check if the `size` property exist on cache. I think there is the issue. Maybe you should use an if else statement to make sure the `size` property do exists. I think your problem is something pretty easy. It is just hard to guess without seeing the .hbs view part of it. –  May 01 '20 at 17:25
  • No problem while using `.size`, I get error when I try to use proto method. – Kaan May 01 '20 at 17:43