handlebars.js: Handlebars: Access has been denied to resolve the property "..." because it is not an "own property" of its parent.
Since Handlebars 4.6.0, templates cannot access prototype properties and methods anymore (by default). See #1633 for discussios, reasons and justifications.
There are runtime options to restore and control the old behavior (see https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access), but if you are using a framework instead of Handlebars core, it might not be clear how to set them.
If you get this error message and please add a comment with the following information
- Which framework (i.e
express-hbs,express-handlebars) is calling Handlebars when the error is logged? (Paste the output ofnpm ls handlebarsoryarn why handlebars, if unsure). - If you use
Handlebars.compileand the resulting template-function directly, you answer should be here https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access. If the documentation doesn’t answer your question or you don’t understand it, please ask (here) so that the documentation can be improved.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 15
Frameworks:
express-handlebarsin conjunction withmongooseThe models of Mongoose are classes and the properties are not “own properties” of the parent object.
The cleanest method is to make sure the the handlebars-input is a proper plain javascript object. This can be done in Mongoose, by calling
toJSON()ortoObjectThe
runtimeOptions(ortemplateOptions) mentioned in the documenation cannot be used here, becauseexpress-handlebarsdoes not support setting them.The quick-and-dirty hack (which is really hacky and I don’t propose is), is to use
Please add a Rocket-emoji to this comment if you would like to have a
Handlebars.createWithAllowedProtoAccessor something like that that does the middle part for you.@Invogue01 You should be able to use the
runtimeOptionsparameter in express-handlebars