Handlebars.js: ハンドルバー:プロパティ「...」は親の「独自のプロパティ」ではないため、アクセスが拒否されました。

作成日 2020年01月18日  ·  13コメント  ·  ソース: handlebars-lang/handlebars.js

Handlebars 4.6.0以降、テンプレートはプロトタイプのプロパティとメソッドにアクセスできなくなりました(デフォルト)。 議論、理由、正当化については、#1633を参照してください。

古い動作を復元および制御するためのランタイムオプションがあります(https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-accessを参照)が、代わりにフレームワークを使用している場合ハンドルバーコアの場合、それらを設定する方法が明確でない場合があります。

このエラーメッセージが表示された場合は、次の情報を含むコメントを追加してください

  • エラーがログに記録されたときにハンドルバーを呼び出しているフレームワーク(つまり、 express-hbsexpress-handlebars )はどれですか? (不明な場合は、 npm ls handlebarsまたはyarn why handlebarsの出力を貼り付けます)。
  • Handlebars.compileと結果のtemplate-functionを直接使用する場合は、 https: //handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-accessに回答する必要があります。 ドキュメントがあなたの質問に答えないか、あなたがそれを理解していないならば、ドキュメントが改善されることができるように(ここで)尋ねてください。

最も参考になるコメント

フレームワーク: express-handlebarsmongooseの組み合わせ

Mongooseのモデルはクラスであり、プロパティは親オブジェクトの「独自のプロパティ」ではありません。

最もクリーンな方法は、handlebars-inputが適切なプレーンjavascriptオブジェクトであることを確認することです。 これは、マングースでtoJSON()またはtoObjectを呼び出すことで実行できます。

app.get('/test', function (_req, res) {
    Kitten.find({}).then(kittens => {
        res.render('test.hbs', {
            kittens: kittens.map(kitten => kitten.toJSON())
        })
    })
});

express-handlebarsは設定をサポートしていないため、ドキュメントに記載されているruntimeOptions (またはtemplateOptions )はここでは使用できません。

迅速で汚いハック(これは本当にハッキーであり、私は提案しません)は、使用することです

var handlebarsInstance = Handlebars.create();

handlebarsInstance.compile = function (templateStr, compileOptions) {
   // compile template
   // return a function that calls the compiled template with  `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options
  // WARNING: People can crash your system by frabricating special templates. Don't use
  // this if your users can create templates. 
}
app.engine('hbs', expressHandlebars({
    handlebars: handlebarsInstance
}));

Handlebars.createWithAllowedProtoAccessなどの中間部分を使用したい場合は、このコメントにロケット絵文字を追加してください。

全てのコメント13件

フレームワーク: express-handlebarsmongooseの組み合わせ

Mongooseのモデルはクラスであり、プロパティは親オブジェクトの「独自のプロパティ」ではありません。

最もクリーンな方法は、handlebars-inputが適切なプレーンjavascriptオブジェクトであることを確認することです。 これは、マングースでtoJSON()またはtoObjectを呼び出すことで実行できます。

app.get('/test', function (_req, res) {
    Kitten.find({}).then(kittens => {
        res.render('test.hbs', {
            kittens: kittens.map(kitten => kitten.toJSON())
        })
    })
});

express-handlebarsは設定をサポートしていないため、ドキュメントに記載されているruntimeOptions (またはtemplateOptions )はここでは使用できません。

迅速で汚いハック(これは本当にハッキーであり、私は提案しません)は、使用することです

var handlebarsInstance = Handlebars.create();

handlebarsInstance.compile = function (templateStr, compileOptions) {
   // compile template
   // return a function that calls the compiled template with  `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options
  // WARNING: People can crash your system by frabricating special templates. Don't use
  // this if your users can create templates. 
}
app.engine('hbs', expressHandlebars({
    handlebars: handlebarsInstance
}));

Handlebars.createWithAllowedProtoAccessなどの中間部分を使用したい場合は、このコメントにロケット絵文字を追加してください。

私はこの問題を抱えています、そしてそれを修正する方法がわかりません、あなたは私を助けることができますか?

ハンドルバーを使用するときにこのエラーを修正する方法を教えてもらえますか?
間違い:
En-US:ハンドルバー:プロパティ「name」は親の「独自のプロパティ」ではないため、アクセスが拒否されました。
ランタイムオプションを追加して、検証またはこの警告を無効にすることができます。

ハンドルバーを使用するときにこのエラーを報告する方法を知っている人はいますか?
間違い:
En:ハンドルバー:「name」プロパティは父親の「自分のプロパティ」ではないため、アクセスが拒否されました。

ランタイムオプションを追加して、検証またはこの警告を無効にすることができます。

私のはこのようなものです:
const handlebars = require( 'express-handlebars')

app.engine( 'handlebars'、handlebars({defaultLayout: 'main'}))
app.set( 'ビューエンジン'、 'ハンドルバー')

app.get( '/ payment'、function(req、res){
Payment.findAll()。then(function(payments){
res.render( '支払い'、{支払い:支払い})
})

拡張機能を使用したいと思います。 の
拡張機能を使用したいと思います。 br

これを見てください: https ://www.npmjs.com/package/@handlebars/allow -prototype-access

express-handlebarsは設定をサポートしていないため、ドキュメントに記載されているruntimeOptions (またはtemplateOptions )はここでは使用できません。

express-handlebarsではこれらのランタイム構成オプションを設定できないため、express-handlebarsにハンドルバー4.5.3を使用させる方法を知っている人はいますか?

https://www.npmjs.com/package/@handlebars/allow -prototype-accessをexpress-handlebarsで使用できます。 コンパイルされたテンプレートをラップして、デフォルトのパラメーターが設定されるようにします。

こんにちはニルス、私はそのパッケージを動作させることができません、そのパッケージで実行しようとすると、「エラー:モジュール「ハンドルバー」はビューエンジンを提供しません」を受け取ります。 エラー。 https://github.com/wycats/handlebars.js/issues/1648で別のユーザーが同様の問題に遭遇しているようです。 同じスレッドに結果を投稿しました。 ありがとう

@ craj1031tx #1648で答えました。

フレームワーク: express-handlebarsmongooseの組み合わせ

Mongooseのモデルはクラスであり、プロパティは親オブジェクトの「独自のプロパティ」ではありません。

最もクリーンな方法は、handlebars-inputが適切なプレーンjavascriptオブジェクトであることを確認することです。 これは、マングースでtoJSON()またはtoObjectを呼び出すことで実行できます。

app.get('/test', function (_req, res) {
    Kitten.find({}).then(kittens => {
        res.render('test.hbs', {
            kittens: kittens.map(kitten => kitten.toJSON())
        })
    })
});

express-handlebarsは設定をサポートしていないため、ドキュメントに記載されているruntimeOptions (またはtemplateOptions )はここでは使用できません。

迅速で汚いハック(これは本当にハッキーであり、私は提案しません)は、使用することです

var handlebarsInstance = Handlebars.create();

handlebarsInstance.compile = function (templateStr, compileOptions) {
   // compile template
   // return a function that calls the compiled template with  `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options
  // WARNING: People can crash your system by frabricating special templates. Don't use
  // this if your users can create templates. 
}
app.engine('hbs', expressHandlebars({
    handlebars: handlebarsInstance
}));

Handlebars.createWithAllowedProtoAccessなどの中間部分を使用したい場合は、このコメントにロケット絵文字を追加してください。

ありがとう、相棒 :)

ロケットを置いておきます!

SequelizeでExpress-Handlebarsを使用しています。
npm lsハンドルバー:

+-- [email protected]
| `-- [email protected] 
`-- [email protected] 

コンソール出力:

Handlebars: Access has been denied to resolve the property "name" 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
Handlebars: Access has been denied to resolve the property "id" 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
Handlebars: Access has been denied to resolve the property "email" 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
Handlebars: Access has been denied to resolve the property "url" 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
Handlebars: Access has been denied to resolve the property "description" 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
Handlebars: Access has been denied to resolve the property "createdAt" 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
Handlebars: Access has been denied to resolve the property "updatedAt" 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

マングースの解決策を試してみます

フレームワーク: express-handlebarsmongooseの組み合わせ

Mongooseのモデルはクラスであり、プロパティは親オブジェクトの「独自のプロパティ」ではありません。

最もクリーンな方法は、handlebars-inputが適切なプレーンjavascriptオブジェクトであることを確認することです。 これは、マングースでtoJSON()またはtoObjectを呼び出すことで実行できます。

app.get('/test', function (_req, res) {
    Kitten.find({}).then(kittens => {
        res.render('test.hbs', {
            kittens: kittens.map(kitten => kitten.toJSON())
        })
    })
});

express-handlebarsは設定をサポートしていないため、ドキュメントに記載されているruntimeOptions (またはtemplateOptions )はここでは使用できません。

迅速で汚いハック(これは本当にハッキーであり、私は提案しません)は、使用することです

var handlebarsInstance = Handlebars.create();

handlebarsInstance.compile = function (templateStr, compileOptions) {
   // compile template
   // return a function that calls the compiled template with  `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options
  // WARNING: People can crash your system by frabricating special templates. Don't use
  // this if your users can create templates. 
}
app.engine('hbs', expressHandlebars({
    handlebars: handlebarsInstance
}));

Handlebars.createWithAllowedProtoAccessなどの中間部分を使用したい場合は、このコメントにロケット絵文字を追加してください。

以下に示すように、lean()メソッドを使用することもできます。

 app.get('/test', function (_req, res) {
    Kitten.find().lean().then(kittens => res.render('test.hbs', { kittens: kittens}));
});

express-handlebarsではこれらのランタイム構成オプションを設定できないため、express-handlebarsにハンドルバー4.5.3を使用させる方法を知っている人はいますか?

エクスプレスハンドルバーにランタイム構成オプションを追加できるようにするPRを作成しました。 https://github.com/express-handlebars/express-handlebars/pull/53

このページは役に立ちましたか?
0 / 5 - 0 評価