handlebars-loader icon indicating copy to clipboard operation
handlebars-loader copied to clipboard

How to set runtime options

Open aromot opened this issue 5 years ago • 2 comments

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?

aromot avatar Jan 12 '20 13:01 aromot

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?

Mehdi-Azmoudeh avatar Apr 11 '20 12:04 Mehdi-Azmoudeh

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;
	}
}

Lukasss93 avatar Apr 11 '20 13:04 Lukasss93