Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set runtime options #192

Open
aromot opened this issue Jan 12, 2020 · 2 comments
Open

How to set runtime options #192

aromot opened this issue Jan 12, 2020 · 2 comments

Comments

@aromot
Copy link

aromot commented Jan 12, 2020

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?

@Mehdi-Azmoudeh
Copy link

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?

@Lukasss93
Copy link

Lukasss93 commented Apr 11, 2020

handlebars-lang/handlebars.js#1637 (comment)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants