handlebars-loader
handlebars-loader copied to clipboard
How to set runtime options
Hello,
I've just updated handlebars to version 4.7.1. I get several errors in the console which look like:
Handlebars: Access has been denied to resolve the property "format" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
This comes from recent changes done in v. 4.7. I'd like to change my webpack loader config to use the documented runtime options (allowProtoPropertiesByDefault
and allowProtoMethodsByDefault
). I've tried:
module: {
rules: [
// few other loaders...
{
test: /\.hbs$/,
loader: 'handlebars-loader',
query: {
precompileOptions: {
allowProtoPropertiesByDefault: true,
allowProtoMethodsByDefault: true
},
helperDirs: [path.join(__dirname, 'src/view/helpers')]
}
}
]
}
But I still get the same problem. How to set these runtime options?
hi, did you solved it? how? I really need to know the solution...
someone told you "to pass the options as second parameter", but where is it? can you show me some example?
https://github.com/wycats/handlebars.js/issues/1637#issuecomment-573417820
I've resolved the problem like this:
import * as CommentTemplate from "../../templates/newsfeed/comment.hbs";
import * as LikeWidgetTemplate from "../../templates/newsfeed/like-widget.hbs";
export default class Comment {
public getCommentTemplate() {
let template = CommentTemplate(this, {
allowProtoMethodsByDefault: true,
allowProtoPropertiesByDefault: true
});
return template;
}
public getLikeWidgetTemplate() {
let template = LikeWidgetTemplate(this, {
allowProtoMethodsByDefault: true,
allowProtoPropertiesByDefault: true
});
return template;
}
}